How to disable a test suite, i.e. all tests inside class extending FunSpec
?
The only solution I'd found is to replace it
with ignore
in front of each test, but it is boring to do so with the dozens of tests.
How to disable a test suite, i.e. all tests inside class extending FunSpec
?
The only solution I'd found is to replace it
with ignore
in front of each test, but it is boring to do so with the dozens of tests.
The easy way to do this in 1.8 is to add a constructor that takes a dummy argument. ScalaTest (and sbt) won't discover the class if it doesn't have a public, no-arg constructor:
class MySuite(ignore: String) extends FunSuite {
// ...
}
In 2.0 you'll be able to just write @Ignore on the class:
@Ignore
class MySuite extends FunSuite {
// ...
}
You can use @Ignore both for distinct tests and the whole suit.
Per scalatest docs, say if you have a test suite like this
describe ("some component") {
it ("should do something") {
...
}
it ("should also do something else") {
...
}
}
To disable just a single test, you can use the ignore()
method.
describe ("some component") {
ignore ("should do something") {
...
}
...
}
Use @DoNotDiscover
From the scaladoc:
import org.scalatest._
@DoNotDiscover
class SetSpec extends FlatSpec {
"An empty Set" should "have size 0" in {
assert(Set.empty.size === 0)
}
it should "produce NoSuchElementException when head is invoked" in {
intercept[NoSuchElementException] {
Set.empty.head
}
}
}
Tag the troublesome tests and then exclude or include tests based on the tag.
Tagging is a one time effort.
Tags are one option, but you need to tag each tests accordingly, you cannot exclude complete suits that way. However, as user272735 mentioned, tagging tests is a one time effort.
Another option is defining a master suite and limiting the list of nestedSuites
to the suites you would like to run (see the docs). The obvious disadvantage is, that you have to maintain the master test suite, i.e., add newly created test suites to it. You could avoid this by recursing through your folders, creating a list of all test suits that can be found, and subtracting those that you put into a black list. In addition, recursing through your folders already gives you an opportunity the filter out files that match an (externally) given criterion.
A third option - albeit more hacky - is to change the package to which the suites you want to black list belong. You can then use a test runner to only run suits included in certain packages. Read more in the docs, section "Specifying 'members-only' and 'wildcard' Suite paths".
© 2022 - 2024 — McMap. All rights reserved.