2

使用ScalaTest'sorg.scalatest.FlatSpecLike时,我可以创建一个 Fixture 并将其混合到测试中,如下所示:

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

in new Fixture { implicit session =>
[error]                                                                                                                          ^
[error] one error found
[error] (Test / compileIncremental) Compilation failed

Intellij 显示类似Type mismatch, expected () => Any, actual: Foo.this.Fixture with Object { ... }

4

0 回答 0