Search code examples
unit-testingplayframeworksbt

sbt testOnly not working


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


Solution

  • 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.