scala - Specs2 顺序关键字

标签 scala testing specs2

当我在 Junit 中运行测试时,无法保证它们的顺序。默认情况下,specs2 并行运行示例,因此这里也不能保证顺序。但是,如果我添加 sequential 关键字,测试将按顺序执行(至少从表面上看是这样)。有没有办法获得顺序行为但让示例以随机顺序运行?

最佳答案

您可以将最新的 specs2 2.3-SNAPSHOT 版本与 random 命令行参数(或规范内的 args.execute(random=true))一起使用:

class TestSpec extends Specification { def is = s2"""

  test1 $e1
  test2 $e2
  test3 $e3

  """

  def e1 = { "starting e1".pp; Thread.sleep(30); "e1".pp; ok }
  def e2 = { "starting e2".pp; Thread.sleep(20); "e2".pp; ok }
  def e3 = { "starting e3".pp; Thread.sleep(40); "e3".pp; ok }
}

sbt> testOnly *TestSpec* -- random

starting e3
e3
starting e2
e2
starting e1
e1
[info] TestSpec
[info]
[info]   + test1
[info]   + test2
[info]   + test3
[info]

关于scala - Specs2 顺序关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18942477/

相关文章:

unit-testing - 使用specs2进行序列空测试

scala - Specs2:如何测试具有多个注入(inject)依赖项的类?

android - Scala Actor 线程控制

java - 将流转换为字符串 block ,反之亦然

ruby-on-rails - 目录 : integration test fail

android - Google Play Alpha 测试 - 无可用更新

scala - 如何使用specs2模拟某些方法仅在第一次抛出异常然后不执行任何操作?

scala - 如何将 Seq[Try] 转换为 Try[Seq]

scala - 使用 Kafka 在长时间运行的 Spark 作业之间进行通信

linux - 在 HPC 上自动测试来自 SVN 的二进制文件