I'm new to Scala. Coming from Java, I'm use to group/bundle my test classes in (JUnit) suites, in a hierarchical matter (suites within suites).
I'm looking for an alternative to this in ScalaTest.
Any Suite can contain nested Suites. These are returned from the nestedSuites lifecyle method. You can use the Suites class to do this:
http://doc.scalatest.org/2.2.4/index.html#org.scalatest.Suites
If you want to disable discovery of the nested suites, you can use the @DoNotDiscover annotation:
http://doc.scalatest.org/2.2.4/index.html#org.scalatest.DoNotDiscover
Both FunSpec
and FreeSpec
allow nesting as much as you want. Examples from http://www.scalatest.org/user_guide/selecting_a_style:
import org.scalatest.FunSpec
class SetSpec extends FunSpec {
describe("A Set") {
describe("when empty") {
it("should have size 0") {
assert(Set.empty.size == 0)
}
it("should produce NoSuchElementException when head is invoked") {
intercept[NoSuchElementException] {
Set.empty.head
}
}
}
}
// just add more describe calls
}
and
import org.scalatest.FreeSpec
class SetSpec extends FreeSpec {
"A Set" - {
"when empty" - {
"should have size 0" in {
assert(Set.empty.size == 0)
}
"should produce NoSuchElementException when head is invoked" in {
intercept[NoSuchElementException] {
Set.empty.head
}
}
}
// add more - calls
}
// add more - calls
}