并行执行测试

编程入门 行业动态 更新时间:2024-10-22 19:30:16
本文介绍了并行执行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到 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.

还有比

  • 将所有测试设置为串行运行,
  • 为每个测试使用单独的文件名和拆解?
  • 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 默认同时运行您的所有规范示例.

    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 { ... } }

    更多推荐

    并行执行测试

    本文发布于:2023-11-10 22:08:07,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1576588.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:测试

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!