scct

Scala Code Coverage Tool

<Name_Pending>

maven-repo

Fork me on GitHub

Eh?

scct is a code coverage tool for Scala.

News

Dec 9, 2012 Support for scala 2.10.0-RC3 and (hopefully) up.

Aug 2, 2012 0.2-SNAPSHOT is out! Multiproject goodness for both sbt and maven.

Feb 25, 2012 Instructions for Maven updated, should work properly now.

Nov 12, 2011 Scala 2.9.1 support.

Jun 4, 2011 Now theoretically supports scala 2.9.0-1 and up. Give it a try!

What's it look like?

scct-screenshot

What's missing?

Mainly, a better-lookin' report UI, a simpler maven configuration.

Usage

The current 0.2-SNAPSHOT version of scct and it's build-tool plugins for sbt and maven only support scala 2.9 and up, sbt 0.12 and up, and maven 3.0.3 and up.

(The old 0.1-SNAPSHOT version supported older versions of scala and sbt. Instructions for the 0.1-SNAPSHOT version are here.)

Firstly...

Add the plugin to your build with the following in project/build.sbt:

resolvers += Classpaths.typesafeResolver

resolvers += "scct-github-repository" at "http://mtkopone.github.com/scct/maven-repo"

addSbtPlugin("reaktor" % "sbt-scct" % "0.2-SNAPSHOT")
				

Single project builds

Add the plugin settings to your project, at build.sbt:

seq(ScctPlugin.instrumentSettings : _*)
        

Run your unit tests with:

$ sbt clean scct:test

Then open:

./target/scala_2.9.2/coverage-report/index.html

Multiproject builds

Add the plugin instrumentation settings to child projects and the report merging settings to the parent project.

For example project/MyBuild.scala:

object MyBuild extends Build {
  lazy val root = Project(id = "parent", base = file("."))
      settings (ScctPlugin.mergeReportSettings: _*) aggregate(first, second)

  lazy val firstChild = Project(id = "firstchild", base = file("first"))
      settings (ScctPlugin.instrumentSettings: _*)

  lazy val secondChild = Project(id = "secondchild", base = file("second"))
      settings (ScctPlugin.instrumentSettings: _*)
}
        

Run coverage for all child projects with:

$ sbt clean scct:test

This creates individual coverage reports into $childProjectDir/target/scala_<ver>/coverage-report/

Merge all the existing child reports into $parentProjectDir/target/scala_<ver>/coverage-report/ with:

$ sbt scct-merge-report

...Enjoy

Firstly...

Assuming you are using maven-scala-plugin...

First, make sure your main and test scalac binding goals are separated in the plugin configuration and have referenceable ID's, so we can extend the main compilation with instrumentation support. Something like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.scala-tools</groupId>
      <artifactId>maven-scala-plugin</artifactId>
      <executions>
        <execution>
          <id>main-scalac</id>
          <goals><goal>compile</goal></goals>
        </execution>
        <execution>
          <id>test-scalac</id>
          <goals><goal>testCompile</goal></goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
				

Then add a custom profile which binds the coverage instrumentation to the main compilation goal by ID, and sets all the necessary environment variables for the test run:

<profiles>
  <profile>
    <id>coverage</id>
    <repositories>
      <repository>
        <id>scct-repo</id>
        <url>http://mtkopone.github.com/scct/maven-repo</url>
      </repository>
    </repositories>
    <dependencies>
      <dependency>
        <groupId>reaktor</groupId>
        <artifactId>scct_2.9.2</artifactId>
        <version>0.2-SNAPSHOT</version>
      </dependency>
    </dependencies>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.6</version>
          <configuration>
            <systemPropertyVariables>
              <scct.project.name>${project.name}</scct.project.name>
              <scct.coverage.file>${project.build.outputDirectory}/coverage.data</scct.coverage.file>
              <scct.report.dir>${project.build.directory}/coverage-report</scct.report.dir>
              <scct.source.dir>${project.build.sourceDirectory}</scct.source.dir>
            </systemPropertyVariables>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.scala-tools</groupId>
          <artifactId>maven-scala-plugin</artifactId>
          <executions>
            <execution>
              <id>main-scalac</id>
              <configuration>
                <args>
                  <args>-P:scct:projectId:${project.name}</args>
                  <args>-P:scct:basedir:${project.basedir}</args>
                </args>
                <compilerPlugins>
                  <compilerPlugin>
                    <groupId>reaktor</groupId>
                    <artifactId>scct_2.9.2</artifactId>
                    <version>0.2-SNAPSHOT</version>
                  </compilerPlugin>
                </compilerPlugins>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>
				

Run your unit tests with:

$ mvn -Pcoverage clean test

Then open:

./target/coverage-report/index.html

Multiproject builds

Add the following bits and pieces to your parent pom:

<pluginRepositories>
  <pluginRepository>
    <id>scct-plugin-repo</id>
    <url>http://mtkopone.github.com/scct/maven-repo</url>
  </pluginRepository>
</pluginRepositories>
...
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-site-plugin</artifactId>
      <version>3.1</version>
      <configuration>
        <reportPlugins>
          <plugin>
            <groupId>reaktor.scct</groupId>
            <artifactId>maven-scct-multiproject-report</artifactId>
            <version>2.0-SNAPSHOT</version>
          </plugin>
        </reportPlugins>
      </configuration>
    </plugin>
  </plugins>
</build>
        

Then run coverage for all child projects with:

$ mvn -Pcoverage clean test

This creates individual coverage reports into $childProjectDir/target/coverage-report/

Merge all the existing child reports into $parentProjectDir/target/site/coverage-report/ with:

$ mvn reaktor.scct:maven-scct-multiproject-report:scct-report

...Enjoy.

Download scct jar.

Compile and instrument your source:

$ scalac -Xplugin:scct_2.9.2-0.2-SNAPSHOT.jar \\
	  -classpath .:scct_2.9.2-0.2-SNAPSHOT.jar Test.scala
				

Run something:

$ scala -classpath .:scct_2.9.2-0.2-SNAPSHOT.jar Test

Then open:

./index.html