【发布时间】:2014-08-26 09:55:44
【问题描述】:
我正在使用 Playframework 编写测试,我需要创建一个临时文件。
@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中创建一个临时文件,并在测试后自动删除?
【问题讨论】: