| --- |
| layout: post |
| status: PUBLISHED |
| published: true |
| title: Using Scala Code Coverage Tool (SCCT) in ESME |
| id: 0ba1d162-891d-4c19-b932-7ead924ff5e5 |
| date: '2011-02-03 08:31:20 -0500' |
| categories: esme |
| tags: |
| - esme |
| - testing |
| permalink: esme/entry/using_scala_code_coverage_tool |
| --- |
| <div> |
| <h3>Blog Author: Vladimir Ivanov</h3> |
| <h3>Introduction</h3> |
| <p>Scala Code Coverage Tool (SCCT) is a code coverage tool written in Scala and configured as SBT plugin (while integration with Maven is also possible). As for any large project, test are vital for ESME as they gurantee that application works as expected. SCCT gathers data (after source code instrumentation phase) while tests are being run and generates user-friendly report and statistics related to test coverage of source code.</p> |
| <p><span style="font-weight: bold; ">Installation and configuration</span></p> |
| <p><span style="background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Introducing SCCT support to ESME project is a matter of adding SBT plugin and consists of two steps: mixin project definition file with new trait as well as adding new repo and dependency to plugin definition file. Scala 2.8.1-compatible version of SCCT plugin is used in this article, but version for 2.7 is also available.</span></p> |
| <h3>Project File</h3> |
| <p>Project definition class for web project EsmeProject should mixin with ScctProject trait:</p> |
| <p><font face="'courier new', courier, monospace"><span style="border-collapse: collapse; ">import reaktor.scct.ScctProject</span></font></p> |
| <p><font face="'courier new', courier, monospace"><span style="font-family: arial, sans-serif; border-collapse: collapse; "></span>class EsmeProject(info: ProjectInfo) extends DefaultWebProject(info) with ScctProject </font></p></p> |
| <p><span style="font-family: arial, verdana, 'Bitstream Vera Sans', helvetica, sans-serif; font-size: 14px; font-weight: bold; ">Plugins</span></p> |
| <p><span class="Apple-tab-span"> </span>SCCT related configuration in plugin definition file is shown below:</p></div> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <div> |
| <pre>class Plugins(info : ProjectInfo) extends PluginDefinition(info) {</pre> |
| </p></div> |
| </blockquote> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <div><span class="Apple-tab-span"> </p> |
| <pre>...</pre> |
| <p></span></div> |
| </blockquote> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <div><span class="Apple-tab-span"> </p> |
| <pre>val scctRepo = "scct-repo" at "http://mtkopone.github.com/scct/maven-repo/"</pre> |
| <p></span></div> |
| </blockquote> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <div><span class="Apple-tab-span"> </p> |
| <pre>lazy val scctPlugin = "reaktor" % "sbt-scct-for-2.8" % "0.1-SNAPSHOT"</pre> |
| <p></span></div> |
| </blockquote> |
| </blockquote> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <div><span class="Apple-tab-span"> </p> |
| <pre>}
|
| <p> </p><p> </p></pre> |
| <p></span></div> |
| </blockquote> |
| <div><span class="Apple-tab-span"> </p> |
| <h3>Running</h3> |
| <p></span><br />To collect test coverage data with SBT its neccessary to perform following command in SBT console:</p> |
| <p><span class="Apple-tab-span"> </span></div> |
| <blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "> |
| <div><font face="'courier new', courier, monospace">sbt> test-coverage</font></div> |
| </blockquote> |
| <div> |
| <p>Report files will be produced in ESME_ROOT/server/target/scala_2.8.1/coverage-report/ directory after all tests have been run. Open index.html file in your browser to see the results*. </p> |
| <p>Here is a video explaining the test results. </p> |
| <p> <iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/u9KJQNewccY" frameborder="0"></iframe> </p> |
| <h3>Notes<span class="Apple-tab-span"> </span></h3> |
| <ul> |
| <ul> |
| <li>Chrome browser is currently not supported. </li> |
| <li>Also note that SCCT tool is still in beta.</li> |
| </ul> |
| </ul> |
| <h3>Links</h3> |
| <p>Mikko Koponen is the author of SCCT tool. Here is the project page on <a href="https://github.com/mtkopone/scct" target="_blank">github</a>. Here is the <a href="http://mtkopone.github.com/scct/" target="_blank">SCCT home page</a>. <br /><span style="white-space: pre-wrap; "><br /></span> |
| </div> |