This might be something that is known to most, but struck me as a surprise.
Given the following test:
import org.scalatest.{BeforeAndAfterAll, FunSpec}
class MyFunSpecTest extends FunSpec with BeforeAndAfterAll {
override def beforeAll {
println("Inside beforeAll")
}
describe("Testing something") {
println("Inside describe")
it("should fail") {
println("Inside it")
fail("not yet implemented")
}
}
}
I would have anticipated output:
Inside beforeAll
Inside describe
Inside it
[info] MyFunSpecTest:
[info] Testing something
[info] - should fail *** FAILED ***
[info] not yet implemented (MyFunSpec.scala:12)
Instead the output is:
Inside describe
Inside beforeAll
Inside it
[info] MyFunSpecTest:
[info] Testing something
[info] - should fail *** FAILED ***
[info] not yet implemented (MyFunSpec.scala:12)
This at least with scalatest_2.9.1 versions 2.0.M5b and 2.0.M5.
The way we found this out was with Selenium tests where we created web driver in beforeAll
- hook and used it in tests. For as long as we initialized lazy val
s in describe
block and used them within it
block there were no problems since computation was delayed until it
, in which state beforeAll
was already executed. Problems naturally occurred the first time we introduced something that was computed in describe
block and depended on the web driver (which was not constructed at this point).