gpt4 book ai didi

Scalatest - 并行套件

转载 作者:行者123 更新时间:2023-12-03 19:05:42 25 4
gpt4 key购买 nike

我正在使用一个套件(Scalatest 版本:3.2.2),里面有几个 TestSuites:

class SuiteMixedSequentialParallel
extends Stepwise(
new TestInParallel,
new TestSequentially
)
现在,我希望所有的测试都在 TestInParallel 中应该并行执行, TestSequentially 中的所有测试应该顺序执行。
因此我延长了 TestInParallel来自 ParallelTestExecution
class TestInParallel extends AnyFunSuite with ParallelTestExecution {
(0 to 10).foreach(i =>
test(s"$i") {
Thread.sleep(500)
println(s"TestInParallel $i")
}
)
}
class TestSequentially extends AnyFunSuite {
(0 to 10).foreach(i =>
test(s"$i") {
Thread.sleep(200)
println(s"TestSequentially $i")
}
)
}
当我跑 sbt testOnly TestInParallel ,所有测试都是并行执行的。
但:
当我跑 sbt testOnly SuiteMixedSequentialParallel ,所有测试都按顺序执行。
有没有人有提示,如何实现,我在 TestInParallel 中的测试将并行运行,当我运行时 SuiteMixedSequentialParallel ?
套房 TestInParallelTestSequentially仍应按顺序运行。只是 TestInParallel 中的测试应该并行运行。

最佳答案

来自 Stepwise documentation :

When StepsSuite is executed, regardless of whether a Distributor is passed, it will execute its nested suites sequentially in the passed order: Step1Suite, Step2Suite, Step3Suite, Step4Suite, and Step5Suite.


来自 ParallelTestExecution documentation :

ScalaTest's normal approach for running suites of tests in parallel is to run different suites in parallel, but the tests of any one suite sequentially.


因此,当您将上述两者结合起来时,您会阻止 scalatest 并行运行,甚至 TestInParallel正在按顺序运行。
为了解决这个问题,你需要混合 ParallelTestExecution特质成 SuiteMixedSequentialParallel , 意义:
class SuiteMixedSequentialParallel
extends Stepwise(
new TestInParallel,
new TestSequentially
) with ParallelTestExecution
这将并行运行两个套件, TestInParallel 中的测试并行,以及来自 TestSequentially 的测试,依次。如预期的。
为了验证这一点,我更改了 println来自 Hallo Welt进入 TestInParallel , 和 TestSequentially分别。
我得到的输出是:
TestInParallel 8
TestInParallel 4
TestInParallel 0
TestInParallel 7
TestInParallel 5
TestInParallel 3
TestSequentially 0
TestInParallel 2
TestInParallel 1
TestInParallel 9
TestInParallel 6
TestSequentially 1
TestSequentially 2
TestSequentially 3
TestSequentially 4
TestSequentially 5
TestSequentially 6
TestSequentially 7
TestSequentially 8
TestSequentially 9

关于Scalatest - 并行套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63683141/

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