【发布时间】:2015-11-16 14:13:28
【问题描述】:
我希望能够使用 JUnit 规则,例如 TemporaryFolder 或其他我们已经在内部开发的 TestRules。
实现这一目标的最佳方法是什么?我知道 JUnitSuite,但它似乎没有选择 @Rule 注释。
无论如何,我想使用不同的 ScalaTest 套件。
所以我的问题是:
- ScalaTest 套件是否支持 JUnit 规则?
- 如果没有,是否有一个库可以让使用 Junit
TestRules 成为可能? - 如果没有,如何在 Scala 测试中使用 JUnit
TestRules? - 或者是否有更合适的特定于 Scala 的方法来完成
TemporaryFolder或例如 Stefan Birkner 的 System Rules 提供的内容?
这是我对JUnitSuite 的尝试:
class MyTest extends JUnitSuite {
//@Rule
//val temporaryFolder = new TemporaryFolder() // throws java.lang.Exception: The @Rule 'temporaryFolder' must be public.
@Rule
def temporaryFolder = new TemporaryFolder()
@Test
def test: Unit = {
assert(temporaryFolder.newFile() !== null) // java.lang.IllegalStateException: the temporary folder has not yet been created
}
}
【问题讨论】:
标签: scala unit-testing junit scalatest