scala 如何关闭多项目构建测试的并行执行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11899723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:26:08  来源:igfitidea点击:

How to turn off parallel execution of tests for multi-project builds?

scalasbt

提问by Manuel Bernhardt

I have a multi-project build with tests in sub-projects and in a parent project. The build is aggregated so that the parent project runs all tests in child projects.

我有一个多项目构建,其中包含子项目和父项目中的测试。构建被聚合,以便父项目运行子项目中的所有测试。

I configured it so that there's no parallel execution of tests in both the sub-projects and the parent project, via

我对其进行了配置,以便在子项目和父项目中没有并行执行测试,通过

parallelExecution in Test := false

However, I have the nagging feeling that tests that span over multiple projects are ran in parallel. In the case of one of the sub-projects this is a problem because it mutates state in a test database concurrently, leading to the test to fail.

但是,我有一种唠叨的感觉,即跨越多个项目的测试是并行运行的。对于其中一个子项目,这是一个问题,因为它同时改变了测试数据库中的状态,导致测试失败。

Any ideas as to how to globally switch of parallel execution of tests, between projects?

关于如何在项目之间全局切换并行执行测试的任何想法?

采纳答案by 0__

I think you can apply a setting across projects using scope ThisBuild, like

我认为您可以使用 scope 跨项目应用设置ThisBuild,例如

parallelExecution in ThisBuild := false

I don't know if you can combine that with scope Test, but it might not be necessary.

我不知道你是否可以将它与 scope 结合起来Test,但它可能没有必要。

回答by lisak

To restrict the number of concurrently executing tests in all projects, use:

要限制所有项目中同时执行的测试数量,请使用:

concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)

See sbt documentation

查看sbt 文档

See discussion

讨论

回答by xmar

This worked for me in 1.1.0:

这在 1.1.0 中对我有用:

Test / parallelExecution := false

Test / parallelExecution := false

回答by Boris Stumm

See my answer here How to run subprojects tests (including setup methods) sequentially when testing

在此处查看我的回答如何在测试时按顺序运行子项目测试(包括设置方法)

There is another way to prevent parallel execution. You can make the test tasks of the different projects depend on each other:

还有另一种防止并行执行的方法。你可以让不同项目的测试任务相互依赖:

test in Project2 := (test in Project2).dependsOn(test in Project1).value
parallelExecution in Test in Project2 := false

回答by brunovianarezende

Another possibility, based on https://stackoverflow.com/a/27068019/1922026, is to define a command alias in the root project:

另一种可能性,基于https://stackoverflow.com/a/27068019/1922026,是在根项目中定义命令别名:

.settings(addCommandAlias("test", ";s1/test;s2/test;s3/test"): _*)

where s1, s2 and s3 are the sub-projects. When you are in root project and run "test" the tests will be executed sequentially and in the order defined.

其中 s1、s2 和 s3 是子项目。当您在根项目中并运行“测试”时,测试将按定义的顺序按顺序执行。