Search code examples
scalasbtscalatest

Run only one package test cases scala


I have the package structure as:


    src ->  test -> scala -> notification

Inside notification i have two packages unit and integration.

unit package has the unit tests and integration package has integration tests. I want to execute only the unit test cases. Is there i way i can do it by sbt test only?

for one class, i know it can be done like this: I have tried for the one class but do not know how to do it for a pacakge.

sbt "test:testOnly *LoginServiceSpec"


Solution

  • testOnly allows you to run wildcards using *. So if all your tests are in package namespace x you can call

    > testOnly x.*
    

    This wildcard can be put everythere, so if you have a subpackage in x, but all your tests end with e.g. Spec you could run

    > testOnly x.*Spec
    

    However if you are using integration test I recommend creating a separate configuration for them so that you would run:

    > test
    

    for unit tests and

    > it:test
    

    for integration test. Then you would put them in src/it/scala. directory.

    UPDATE:

    IntegrationTest was deprecated in sbt 1.9.0, now it is recommended to just create a separate module for IT tests.