12
votes

I'm trying to run a single test class in a Java Play project but fails misserably.

If I try to run

testOnly my.app.TheClassTest

from within sbt (as described in JavaTest and sbt test) I get this result:

[info] Passed: Total 0, Failed 0, Errors 0, Passed 0

[info] No tests to run for test:testOnly

My only suspicion is that the message "No tests to run for test:testOnly" does not include the name of the class I try to test.

If I try to run it from command line

sbt testOnly "my.app.TheClassTest"

It runs all the tests and then I get the following error:

[error] Expected ID character

[error] Not a valid command: net (similar: set, new, inspect)

[error] Expected project ID

[error] Expected configuration

[error] Expected ':' (if selecting a configuration)

[error] Expected key

[error] Not a valid key: my (similar: test, name, assets)

[error] my.app.TheClassTest

I've tried all kinds of variations such as testOnly TheClassTest, test-only my.app.TheClassTest, test:testOnly etc. with only minor variations in result. Using testOnly within sbt I can write whatever I feel like and still always get the same response.

Running all tests work fine.

Is there at least a way to get a more

3

3 Answers

14
votes

From sbt you can try to get the autocompletion for the command:

sbt:my-project> testOnly <tab>

When running from command line (so outside the sbt prompt), for example in continuous integration, or other scripts etc., then you take the command in quotes including the argument, like this:

sbt "testOnly my.package.TheClassTest"

Otherwise testOnly does not seem to receive the argument.

10
votes

From sbt you can try to get the autocompletion for the command:

sbt:my-project> testOnly <tab>

It should display the lists of tests classes that are available. This may not work with the oldest versions of sbt.

If you see no classes, try to run test:compile before to compile your test classes.

0
votes

For sbt 1.5.2, this worked:

sbt "project dbm; testOnly my.package.TestClass"