scala - 使用fixture.FlatSpecLike将特征混合到ScalaTest中的测试方法中
问题描述
使用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 { ... }
解决方案
推荐阅读
- android - RecyclerView的父Fragment在内容发生变化时如何重绘
- html - 如何在 CSS 中设置定义的菜单大小?
- c# - 使用 webrequest 和 substring + indexof 从 src 获取 html 元素
- templates - 如何在布局typo3 9中呈现不同的模板?
- c# - 从键盘切换到触摸屏
- python - 在装饰器中记录 funcName 时显示原始函数
- php - 当没有 NULL 值时,Oracle 中出现错误“ORA-01400: cannot insert NULL into ...”
- angular - 如何使用 p-listbox 过滤多个标签?
- webpack - 样式未在组件中导入
- javascript - 我应该如何测试这个角度分量?