Search code examples
scalasbtscalatest

SBT run single test class in submodule


I have a multi module project with moduleA, moduleB, and moduleC. I want to run my class com.helpme.run.MyTest from moduleB.

My guess is the sbt command should look like:

sbt "project moduleA" --mainClass com.helpme.run.MyTest test

But no luck. Please help!! Thanks!


Solution

  • First of all you can run a test by using testOnly

    $ sbt testOnly MyTest
    

    But if your project is a multi-project sbt project and you have the same test class with the same name in more than one project you can navigate between projects by project command and then run the test

    $ sbt
    > project moduleA
    > testOnly MyTest
    

    Note that you have to first run sbt and then run the rest of commands from the sbt shell.