scct

Scala Code Coverage Tool

<Name_Pending>

maven-repo

Fork me on GitHub

Eh?

scct is a code coverage tool for Scala.

News

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, the ability to merge reports, a better-lookin' report UI, a simpler maven configuration.

Usage

Add the following to project/plugins/Plugins.scala:

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val scctRepo = "scct-repo" at "http://mtkopone.github.com/scct/maven-repo/"
  lazy val scctPlugin = "reaktor" % "scct-sbt-for-2.9.1" % "0.1-SNAPSHOT"
}			
				

Have your project extend reaktor.scct.ScctProject:

import sbt._
import reaktor.scct.ScctProject
class MyProject(i: ProjectInfo) extends DefaultProject(i) with ScctProject {
  // ...
}
				

Run your unit tests with:

$ sbt test-coverage

Then open:

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

Enjoy.

Please see https://github.com/dvc94ch/sbt-scct for instruction on usage with sbt 0.10+

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 repository</id>
        <url>http://mtkopone.github.com/scct/maven-repo</url>
      </repository>
    </repositories>
    <dependencies>
      <dependency>
        <groupId>reaktor</groupId>
        <artifactId>scct_2.9.1</artifactId>
        <version>0.1-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>
                <compilerPlugins>
                  <compilerPlugin>
                    <groupId>reaktor</groupId>
                    <artifactId>scct_2.9.1</artifactId>
                    <version>0.1-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

Enjoy.

Download scct jar.

Compile and instrument your source:

$ scalac -Xplugin:scct_2.9.1-0.1-SNAPSHOT.jar \\ 
	  -classpath .:scct_2.9.1-0.1-SNAPSHOT.jar Test.scala
				

Run something:

$ scala -classpath .:scct_2.9.1-0.1-SNAPSHOT.jar Test

Then open:

./index.html

Add the following to project/plugins/Plugins.scala:

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val scctRepo = "scct-repo" at "http://mtkopone.github.com/scct/maven-repo/"
  lazy val scctPlugin = "reaktor" % "scct-sbt-for-2.9" % "0.1-SNAPSHOT"
}			
				

Have your project extend reaktor.scct.ScctProject:

import sbt._
import reaktor.scct.ScctProject
class MyProject(i: ProjectInfo) extends DefaultProject(i) with ScctProject {
  // ...
}
				

Run your unit tests with:

$ sbt test-coverage

Then open:

./target/scala_2.9.0-1/coverage-report/index.html

Enjoy.

Please see https://github.com/dvc94ch/sbt-scct for instruction on usage with sbt 0.10+

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 repository</id>
        <url>http://mtkopone.github.com/scct/maven-repo</url>
      </repository>
    </repositories>
    <dependencies>
      <dependency>
        <groupId>reaktor</groupId>
        <artifactId>scct_2.9.0-1</artifactId>
        <version>0.1-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>
                <compilerPlugins>
                  <compilerPlugin>
                    <groupId>reaktor</groupId>
                    <artifactId>scct_2.9.0-1</artifactId>
                    <version>0.1-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

Enjoy.

Download scct jar.

Compile and instrument your source:

$ scalac -Xplugin:scct_2.9.0-1-0.1-SNAPSHOT.jar \\ 
	  -classpath .:scct_2.9.0-1-0.1-SNAPSHOT.jar Test.scala
				

Run something:

$ scala -classpath .:scct_2.9.0-1-0.1-SNAPSHOT.jar Test

Then open:

./index.html

Add the following to project/plugins/Plugins.scala:

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val scctRepo = "scct-repo" at "http://mtkopone.github.com/scct/maven-repo/"
  lazy val scctPlugin = "reaktor" % "sbt-scct-for-2.8" % "0.1-SNAPSHOT"
}			
				

Have your project extend reaktor.scct.ScctProject:

import sbt._
import reaktor.scct.ScctProject
class MyProject(i: ProjectInfo) extends DefaultProject(i) with ScctProject {
  // ...
}
				

Run your unit tests with:

$ sbt test-coverage

Then open:

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

Enjoy.

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 repository</id>
        <url>http://mtkopone.github.com/scct/maven-repo</url>
      </repository>
    </repositories>
    <dependencies>
      <dependency>
        <groupId>reaktor</groupId>
        <artifactId>scct_2.8.0</artifactId>
        <version>0.1-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>
                <compilerPlugins>
                  <compilerPlugin>
                    <groupId>reaktor</groupId>
                    <artifactId>scct_2.8.0</artifactId>
                    <version>0.1-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

Enjoy.

Download scct jar.

Compile and instrument your source:

$ scalac -Xplugin:scct_2.8.0-0.1-SNAPSHOT.jar \\ 
	  -classpath .:scct_2.8.0-0.1-SNAPSHOT.jar Test.scala
				

Run something:

$ scala -classpath .:scct_2.8.0-0.1-SNAPSHOT.jar Test

Then open:

./index.html

Add the following to project/plugins/Plugins.scala:

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val scctRepo = "scct-repo" at "http://mtkopone.github.com/scct/maven-repo/"
  lazy val scctPlugin = "reaktor" % "sbt-scct" % "0.1-SNAPSHOT"
}			
				

Have your project extend reaktor.scct.ScctProject:

import sbt._
import reaktor.scct.ScctProject
class MyProject(i: ProjectInfo) extends DefaultProject(i) with ScctProject {
  // ...
}
				

Run your unit tests with:

$ sbt test-coverage

Then open:

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

Enjoy.

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 repository</id>
        <url>http://mtkopone.github.com/scct/maven-repo</url>
      </repository>
    </repositories>
    <dependencies>
      <dependency>
        <groupId>reaktor</groupId>
        <artifactId>scct_2.7.7</artifactId>
        <version>0.1-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>
                <compilerPlugins>
                  <compilerPlugin>
                    <groupId>reaktor</groupId>
                    <artifactId>scct_2.7.7</artifactId>
                    <version>0.1-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

Enjoy.

Download scct jar.

Compile and instrument your source:

$ scalac -Xplugin:scct_2.7.7-0.1-SNAPSHOT.jar \\ 
    -classpath .:scct_2.7.7-0.1-SNAPSHOT.jar Test.scala
				

Run something:

$ scala -classpath .:scct_2.7.7-0.1-SNAPSHOT.jar Test

Then open:

./index.html