使用ScalaTest
的{{1}}时,我可以创建一个夹具并将其混合到测试中,如下所示:
org.scalatest.FlatSpecLike
但是,当我改用class Foo extends FlatSpecLike with Matchers {
trait Fixture {
val bar = 2
}
"This test method" should "not cause a compile error" in new Fixture {
2 shouldEqual bar
}
}
时,我不能这样做:
org.scalatest.fixture.FlatSpecLike
有人可以建议我如何使用class Baz extends fixture.FlatSpecLike with Matchers {
trait Fixture {
val bar = 2
}
"This test method" should "cause a compile error" in new Fixture { implicit session =>
...
}
}
将特征混入测试方法吗?
更新:
在fixture.FlatSpecLike
中运行~test:compile
之后,这是编译器的错误:
SBT
Intellij显示类似in new Fixture { implicit session =>
[error] ^
[error] one error found
[error] (Test / compileIncremental) Compilation failed