How to run a single test in scalatest from maven

tl;dr mvn test -Dsuites="some.package.SpecsClass"


I found an answer from here and it works:(https://groups.google.com/forum/#!topic/scalatest-users/Rr0gy61dg-0)

run test 'a pending test' in HelloSuite, and all tests in HelloWordSpec:

 mvn test -Dsuites='org.example.
HelloSuite @a pending test, org.example.HelloWordSpec' 
  • run all tests in HelloSuite containing 'hello':

    mvn test -Dsuites='org.example.HelloSuite hello'

for more details: http://scalatest.org/user_guide/using_the_scalatest_maven_plugin


Found the answer: it is

-DwildcardSuites

So here is the example command line:

mvn -pl streaming -DwildcardSuites=org.apache.spark.streaming.InputStreamSuite test

Update Newer versions of scalatest use

 -Dsuites

So the syntax would be:

mvn -pl streaming -Dsuites=org.apache.spark.streaming.InputStreamSuite test

Note that if you have some Java tests in the same module, as much of spark does, you need to turn them off -which you can do by telling surefire to run a test that isn't there

Here is the test that I've just been running

mvn test -Dtest=moo -DwildcardSuites=org.apache.spark.deploy.yarn.ClientSuite

That skips the java test and only runs the scala one.

One thing which scalatest doesn't seem to do is let you run a single test within a suite, the way maven surefire does. That's not ideal if you have one failing test in a big suite.

[Correction 2016-08-22: looks like you can ask for a specific suite by name; look at the other answers below. Happy to be wrong].