0

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 vals 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).

4

1 回答 1

0

before() 在每个 it() 之前被调用,而不是在每个 describe() 之前。尝试将您的代码移动到 it() 并让我们知道这是否有帮助。

于 2013-05-31T10:17:35.980 回答