我想重寫ScalaTest特徵BeforeAndAfterEach來爲所有測試實現一次這些東西。最後我把它編譯出來,但我不明白爲什麼。覆蓋特徵和自我類型
trait MySetup extends BeforeAndAfterEach {
this : org.scalatest.BeforeAndAfterEach with org.scalatest.Suite =>
var service: String = _
abstract override def beforeEach(): Unit = {
service = "apa"
super.beforeEach()
}
abstract override def afterEach(): Unit = {
service = ""
}
}
是得到它的工作的事情是行:
this : org.scalatest.BeforeAndAfterEach with org.scalatest.Suite =>
我發現它在BeforeAndAfterEach開始執行並複製它。
它做什麼,爲什麼我需要它?
更新:
這是一個更簡單的版本。
trait MySetup extends FlatSpec with BeforeAndAfterEach {
var service: String = _
override def beforeEach {
service = "apa"
super.beforeEach
}
override def afterEach {
service = ""
super.afterEach
}
}
謝謝! ScalaTest鏈接正是我所需要的。 –