TLDR;在一個ScalaTest規範中混合了BeforeAndAfterAll
和ParallelTestExecution
,afterAll()
在每次測試之後被調用,然後在所有的測試之後再次調用。我只想要畢竟的行爲。ScalaTest afterAll()在每次測試後調用
我有一個ScalaTest規格如下:
class TestSpec extends fixture.FunSpec with ShouldMatchers with BeforeAndAfter with BeforeAndAfterAll with ParallelTestExecution {
override def afterAll() = {
println("afterAll")
}
describe("something") {
it("should foo") {
println("foo")
}
it("should bar") {
println("bar")
}
}
}
兩個測試要共享一個夾具,然後afterAll()
應清理夾具。我已經省略了夾具代碼的細節,因爲這個問題並不重要。
這裏是我的測試的輸出:
foo
afterAll
bar
afterAll
afterAll
所以afterAll()
被每次測試後畢竟他們的調用,然後再次。我只希望它在所有測試後被調用。
有誰知道爲什麼afterAll()
的行爲如此?
更新
如果我不ParallelTestExecution
混,我的測試表現正常:
foo
bar
afterAll
不幸的是,其實我是想ParallelTestExecution
。有沒有辦法讓我的蛋糕也吃嗎?