title: Why is code coverage zero with Scalatest, Maven and cobertura?
body: <p>I am trying to get Cobertura to work on a really simple example project with Maven and Scala. 
  Here is my pom:</p>
  
  <p>EDIT: Meanwhile, I found out that this pom is rather bad. If you're looking for a better example, see the one in the accepted answer.</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;sandbox&lt;/groupId&gt;
  &lt;artifactId&gt;sandbox&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;properties&gt;
      &lt;scala.version&gt;2.10.4&lt;/scala.version&gt;
  &lt;/properties&gt;
  
  &lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;scala-tools.org&lt;/id&gt;
          &lt;name&gt;Scala-Tools Maven2 Repository&lt;/name&gt;
          &lt;url&gt;http://scala-tools.org/repo-releases&lt;/url&gt;
      &lt;/repository&gt;
  &lt;/repositories&gt;
  
  &lt;pluginRepositories&gt;
      &lt;pluginRepository&gt;
          &lt;id&gt;scala-tools.org&lt;/id&gt;
          &lt;name&gt;Scala-Tools Maven2 Repository&lt;/name&gt;
          &lt;url&gt;http://scala-tools.org/repo-releases&lt;/url&gt;
      &lt;/pluginRepository&gt;
  &lt;/pluginRepositories&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.scala-lang&lt;/groupId&gt;
          &lt;artifactId&gt;scala-library&lt;/artifactId&gt;
          &lt;version&gt;${scala.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- Scalatest --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.scalatest&lt;/groupId&gt;
          &lt;artifactId&gt;scalatest_2.10&lt;/artifactId&gt;
          &lt;version&gt;2.2.4&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;sourceDirectory&gt;src/main/scala&lt;/sourceDirectory&gt;
      &lt;testSourceDirectory&gt;src/test/scala&lt;/testSourceDirectory&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.scala-tools&lt;/groupId&gt;
              &lt;artifactId&gt;maven-scala-plugin&lt;/artifactId&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;compile&lt;/goal&gt;
                          &lt;goal&gt;testCompile&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;scalaVersion&gt;${scala.version}&lt;/scalaVersion&gt;
                  &lt;args&gt;
                      &lt;arg&gt;-target:jvm-1.5&lt;/arg&gt;
                  &lt;/args&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;!-- disable surefire --&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;skipTests&gt;true&lt;/skipTests&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;!-- enable scalatest --&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.scalatest&lt;/groupId&gt;
              &lt;artifactId&gt;scalatest-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;reportsDirectory&gt;${project.build.directory}/surefire-reports&lt;/reportsDirectory&gt;
                  &lt;junitxml&gt;.&lt;/junitxml&gt;
                  &lt;filereports&gt;WDF TestSuite.txt&lt;/filereports&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;test&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;test&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  
           &lt;!--enable cobertura--&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;cobertura-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;clean&lt;/goal&gt;
                          &lt;goal&gt;cobertura&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;reporting&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.scala-tools&lt;/groupId&gt;
              &lt;artifactId&gt;maven-scala-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;scalaVersion&gt;${scala.version}&lt;/scalaVersion&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;cobertura-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;formats&gt;
                      &lt;format&gt;xml&lt;/format&gt;
                  &lt;/formats&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/reporting&gt;
  </code></pre>
  
  <p></p>
  
  <p>I disabled surefire, enabled Scalatest, and the tests do indeed get executed.</p>
  
  <p>I added the Maven Cobertura plugin to the build and the reporting section of the pom. When I run </p>
  
  <pre><code>mvn clean install cobertura:cobertura -Dcobertura.report.format=xml
  </code></pre>
  
  <p>I do get a coverage report - which states that nothing is covered, coverage is 0%.</p>
  
  <p>Now I tried various things: I played around with the executions part, I moved stuff from the build to the reporting section and vice versa, I tried different Maven goals. It was all in vain - either no report was created or it stated 0% coverage.</p>
  
  <p>I even tried Scoverage! But with similar results.</p>
  
  <p>So I guess I made some very basic mistake. Can anybody point me to it?</p>