Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run just a specific scalatest test from sbt

Tags:

sbt

scalatest

sbt's test-only command can be used to run the tests found in a specific test class. With JUnit tests you can use test-only to run specific methods on a test class e.g. test-only mypackage.MyTestClass.test1Equals1 to run just that method.

Is such a thing possible with scalatest's more free-form test syntax, presumably by working out the name it uses internally to reference a specific test? If it isn't possible in FreeSpec (which is easy to imagine given its nature) is there a way to do it with a simpler testing approach like FunSuite?

like image 579
adamnfish Avatar asked Mar 05 '14 17:03

adamnfish


People also ask

How do you ignore test cases in ScalaTest?

It has been inserted into Scaladoc by pretending it is a trait. When you mark a test class with a tag annotation, ScalaTest will mark each test defined in that class with that tag. Thus, marking the SetSpec in the above example with the @Ignore tag annotation means that both tests in the class will be ignored.

What is ScalaTest sbt?

ScalaTest is one of the main testing libraries for Scala projects, and in this lesson you'll see how to create a Scala project that uses ScalaTest. You'll also be able to compile, test, and run the project with sbt.


1 Answers

For a general solution we need to wait for sbt#911, but apparently ScalaTest 2.1.3 has a support for running a specific test. Seth says:

This is now supported in ScalaTest 2.1.3 with:

test-only *MySuite -- -z foo

to run only the tests whose name includes the substring "foo". For exact match rather than substring, use -t instead of -z.

like image 62
2 revs Avatar answered Oct 02 '22 18:10

2 revs