gpt4 book ai didi

scala - Specs2 顺序关键字

转载 作者:行者123 更新时间:2023-11-28 20:08:50 25 4
gpt4 key购买 nike

当我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com