user2259183
user2259183

Reputation: 23

sbt test a single directory

I am using Play framework. I have multiple scala directories under test and some of them fail to compile. So I want to compile/test a single directory under test. For example say I have a test directory and underneath I have test/dir1, test/dir2 .. dir1 has issues and I don't want to compile/run dir1 classes, just compile/run dir2 classes If I use - > sbt test:testOnly dir2/.. sbt is also compiling dir1 classes which fail. Is there a way to tell sbt to ignore dir1 directory and just test dir2 classes ?

Thanks

Upvotes: 0

Views: 2803

Answers (4)

capo11
capo11

Reputation: 854

with sbt 1.7.1 you can call at the root of the project:

sbt "Test / testOnly *your-directory*"

or

sbt "Test / test/testOnly *dir2*"

Upvotes: 0

pme
pme

Reputation: 14803

Another idea is just to exclude the problematic tests:

With Scala Test you can exclude tests, when you put @DoNotDiscoverto a test class,like:

import org.scalatest.DoNotDiscover

@DoNotDiscover
class AdaptersExtensionsTest extends UnitTest {
..
}

Be aware that this is risky as you may forget about these tests.

Better I think is to ignore tests. In Scala Test depending on your testing flavor you can ignore single or group of tests (check the documentation). Here an example for FeatureSpec:

 ignore(s"Get the OpeningHours from the DataCore webservice.") {
    scenario("Get the OpeningHours for the Center.") {
      Given("The Service is correctly configured.")
      ...
      When("calling the Service.")
      ...
      Then("The OpeningHours have exactly 7 OpeningHour (for each day).")
        assert(...)
      }
    }

This is better as when running the tests you will get warnings for all ignored tests.

Upvotes: 1

laughedelic
laughedelic

Reputation: 6460

I think you can't do it the way you describe, but you have two options:

  • If you systematically want to compile and test those directories separately, you have to put them in separate sbt subprojects.

  • And if you want to exclude just some sources from compilation temporarily while you develop another part of the application, you can do that with the excludeFilter in unmanagedSources sbt key. Like this:

    excludeFilter in unmanagedSources ~= { _ ||  "*/dir2/*" }
    

Upvotes: 0

pme
pme

Reputation: 14803

You can pattern match them:

sbt testOnly *.dir2.*

If you have sub-projects:

sbt server/testOnly *.dir2.*

Here you have sbt sub-project called server

To find out your subprojects, use:

sbt projects

Upvotes: 2

Related Questions