Get ScalaTest to run my tests from Maven

3.7k Views Asked by At

I added this to my pom.xml, straight from the documentation:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
      <junitxml>.</junitxml>
      <filereports>TestSuite.txt</filereports>
    </configuration>
    <executions>
      <execution>
        <id>test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Running mvn test gives me:

Discovery starting.
Discovery completed in 265 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 283 milliseconds.
Total number of tests run: 0
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.

However, there are several tests under src/test/scala which should have been discovered and ran.

I even tried running mvn test-compile compile, just to see if anything showed up. The result is as expected:

[INFO] Nothing to compile - all classes are up to date

So, how come they are not discovered? My files are all named *Test.scala, and are written like in the scalatest documentation.

1

There are 1 best solutions below

0
On

In my current project we have the following configuration in pom.xml:

 <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.2</version>
    <executions>
      <execution>
        <id>compile</id>
        <goals>
          <goal>compile</goal>
        </goals>
        <phase>compile</phase>
      </execution>
      <execution>
        <id>test-compile</id>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <phase>test-compile</phase>
      </execution>
      <execution>
        <phase>process-resources</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
      <stdout>W</stdout>
    </configuration>
    <executions>
      <execution>
        <id>scala-test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

As it is easy to guess first plug-in takes care of compilation and resource processing while the second only runs them during test goal.