简体   繁体   中英

Exclude Specifically Tagged tests from SBT when using ScalaTest

I'm having a lot of frustration trying to run all my tests from sbt - while excluding a specific tag. Here is what I am trying to run:

testOnly * -- -l "com.my.project.path.tags.ValidationTest"

I've tried many variations of this command, including replacing the * with the path to a class or the path to a package like so:

testOnly "com.my.project.path.somePackage" -- -l "com.my.project.path.tags.ValidationTest"

And I've tried with and without quotes around the package.

I just read that testOnly is used in the new version of sbt and not test-only . I've tried this syntax (and many variations), and nothing seems to work. I have my tests set up like this:

"some method" should "fail when doing something" taggedAs ValidationTest in { ... }

I have object ValidationTest extends Tag("com.my.project.path.tags.ValidationTest") defined in TestTag.scala .

I have also attempted this when the method is defined with the it keyword, instead of "some method" should "fail..."

Sbt with ScalaTest shows the following under " Include and Exclude Tests with Tags "

> test-only org.acme.* -- -n CheckinTests
> test-only org.acme.* -- -n FunctionalTests -l org.scalatest.tags.Slow
> test-only org.acme.* -- -n "CheckinTests FunctionalTests" -l "org.scalatest.tags.Slow org.scalatest.tags.Network"

Just a couple of guesses:

  • all this syntax works only from sbt console and DOES NOT work from command line;
  • the package name should be WITHOUT quotes and should end with asterix, the tag should be WITH quotes (eg testOnly com.my.project.* -- -l "com.my.project.path.tags.ValidationTest" )
  • testOnly concerns only unit tests, if you should have integration tests, you should use eg it:testOnly * -- -l "path.to.Tag" .

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