简体   繁体   中英

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

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

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/*" } 

Another idea is just to exclude the problematic tests:

With Scala Test you can exclude tests, when you put @DoNotDiscover to 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.

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*"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM