本文介绍了并行执行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将所有测试设置为串行运行, 为每个测试使用单独的文件名和拆解?
class WriteAndReadSpec extends Specification{
val file = new File("testFiles/tmp.txt")
"WriteAndRead" should {
"work once" in {
new FileWriter(file, false).append("Foo").close
Source.fromFile(file).getLines().toList(0) must_== "Foo"
}
"work twice" in {
new FileWriter(file, false).append("Bar").close
Source.fromFile(file).getLines().toList(0) must_== "Bar"
}
}
trait TearDown extends After {
def after = if(file.exists) file.delete
}
}
推荐答案
我注意到 SBT 正在并行运行我的 specs2 测试.这看起来不错,除了我的一个测试涉及从文件读取和写入,因此无法预测地失败,例如见下文.
I've noticed that SBT is running my specs2 tests in parallel. This seems good, except one of my tests involves reading and writing from a file and hence fails unpredictably, e.g. see below.
还有比
除了上面写的关于 sbt 的内容之外,您必须知道 specs2 默认同时运行您的所有规范示例.
In addition to that is written about sbt above, you must know that specs2 runs all the examples of your specifications concurrently by default.
您仍然可以声明,对于给定的规范,示例必须按顺序执行.为此,您只需添加 sequential 到规范的开头:
You can still declare that, for a given specification, the examples must be executed sequentially. To do that, you simply add sequential to the beginning of your specification:
class WriteAndReadSpec extends Specification{ val file = new File("testFiles/tmp.txt") sequential "WriteAndRead" should { ... } }更多推荐
并行执行测试
发布评论