我正在使用Play框架编写一个测试,需要创建一个临时文件。
@RunWith(classOf[JUnitRunner])
class DiagnosticSpec extends Specification {
@Rule
val temporaryFolder: TemporaryFolder = new TemporaryFolder()
"my test" should {
"run with temporary file" in {
val file = temporaryFolder.newFile() // line.35
// go on with the file
}
}
}
但是当我运行这个测试时,它总是抛出异常:
[error] IllegalStateException: the temporary folder has not yet been created (MyTest.scala:35)
在specs2中可以使用它吗?如果不行,我该如何在specs2中创建一个临时文件,并在测试完成后自动删除它?