Continuous Testing of Scala sources

Prerequisite : common usages

Running all tests

If you want continuous testing of sources under src/main and src/test (files are compiled when they are saved then tests are run whenever a compile succeeds) :

mvn scala:cctest
  • Compilation runs in a infinite loop and compiles only modified files (non-stop), so use Ctrl+C to stop it
  • Tests are run if the compile succeeds
  • If you want to compile without FSC (with regular scalac like non-continuous compilation) :
    mvn scala:cctest -Dfsc=false

Running a subset of tests

To run only a single test each time or test cases matching a particular pattern, supply the test parameter (like the surefire:test goal)

mvn scala:cctest -Dtest=MyTest

Summary of test failures

To get useful output when tests fail (like SBT does by default) please make sure you have configured the surefire plugin to set useFile to false (or to use a maven property in the configuration of the useFile so you can override on the command line) then you get a reasonable report on the console when tests fail; showing the failed assertion and stack traces etc. So adding something like the following to your pom.xml

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <forkMode>once</forkMode>
    <useFile>false</useFile>
  </configuration>
</plugin>
       

Running ScataTest tests

The ccTestGoals parameter can be used to run tests with a different plugin other than the surefire plugin. For example ScalaTest tests can be executed using the maven-scalatst-plugin. To execute continuous tests using the maven-scalatest-plugin, first make sure that the maven-scalatest-plugin is configured in your pom.xml. Then, set the ccTestGoals parameter to execute the `scalatest:test` goal.

From the command line:

mvn -Dcctest.goals=scalatest:test scala:cctest

If you plan to execute ScalaTest often, you can also set the parameter in your pom.xml:

<plugin>
  <groupId>net.alchim31.maven</groupId>
  <artifactId>scala-maven-plugin</artifactId>
  <version>4.8.1</version>
  <configuration>
    <ccTestGoals>scatatest:test</ccTestGoals>
  </configuration>
</plugin>
       

The ccTestGoals parameter takes a space-seperated list of goals. Thus, it is possible to run both JUnit tests and ScalaTest tests:

mvn -Dcctest.goals="surefire:test scalatest:test" scala:cctest

Note

If you want to display command used to run scala :

mvn scala:cctest -DdisplayCmd=true
  • WARNING : continuous compilation is an infinite loop so, avoid call the goal "cctest" in pom.xml or to connect it to a lifecycle's phase.