在类中并行运行 NUnit 测试但不与其他类测试一起运行的方法?

编程入门 行业动态 更新时间:2024-10-28 20:24:40
本文介绍了在类中并行运行 NUnit 测试但不与其他类测试一起运行的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 Visual Studio Professional 2017 中使用 NUnit 3.8.

我在我的 AssemblyInfo.cs 文件中指定了 [assembly: Parallelizable(ParallelScope.Fixtures)].这使得类中的测试的默认行为不能与该类中的其他测试并行运行,但它们可以与其他类的测试并行运行.

I've got [assembly: Parallelizable(ParallelScope.Fixtures)] designated in my AssemblyInfo.cs file. This makes the default behavior that tests within classes cannot run in parallel with other tests within that class, but they can run in parallel with tests of other classes.

我想知道是否有可能保持默认行为,但在逐个类的基础上反转逻辑.我想让测试在特定类中与另一个并行运行,但不与其他类的测试并行运行.

I'm wondering if it's possible to keep that default behavior but invert the logic on a class-by-class basis. I want to have tests within a specific class run in parallel with one another, but not with tests of other classes.

以下面的代码为例.如果我要运行下面的所有测试 - 我希望 TestClassA 中的所有测试并行执行,直到所有测试都完成,然后 TestClassB 中的所有测试将并行执行.

Take the code below. If I were to run all the tests below - I would want all of the tests in TestClassA to execute in parallel until all were done, and THEN all tests from TestClassB would execute in parallel.

[NonParallelizable] public class TestClassA { [Test] [Parallelizable(ParallelScope.Children)] [TestCase(1, 1)] [TestCase(2, 2)] [TestCase(3, 3)] [TestCase(4, 4)] public void TestIntsA(int a, int b) { System.Threading.Thread.Sleep(1000); Assert.AreEqual(a, b); } } [NonParallelizable] public class TestClassB { [Test] [Parallelizable(ParallelScope.Children)] [TestCase(1, 2)] [TestCase(2, 3)] [TestCase(3, 4)] [TestCase(4, 5)] public void TestIntsB(int a, int b) { System.Threading.Thread.Sleep(1000); Assert.AreEqual(a, b); } }

基于本 NUnit 文档(具体摘录如下),我认为这是可能的.

Based on this NUnit documentation (specific excerpt below), I would think this is possible.

具有并行方法的非并行类: 这些方法仅彼此并行运行,不与任何其他类的测试方法并行运行.

Non-parallel class with parallel methods: The methods only run in parallel with one another, not with the test methods of any other classes.

然而,当我用三个工作线程运行上面的代码时,前三个测试成功运行,然后没有更多的测试被启动.测试运行暂停,直到我取消测试运行.

However, when I've run the above code with three worker threads, the first three tests run successfully, and then no more tests are initiated. The test run hangs in limbo until I cancel the test run.

有什么建议吗?

推荐答案

您的代码示例看起来正确.有一些错误,例如 github/nunit/nunit/issues/2438 在 v3.8 中导致测试用例并行化问题.团队目前正在开发 v3.8.2,应该可以解决这些问题.

You code sample looks correct. There's been a few bugs such as github/nunit/nunit/issues/2438 which have caused problems with test case parallelization in v3.8. The team are working on v3.8.2 at the moment, which should resolve these issues.

已经解决了许多问题 - 您可能希望尝试使用最新版本的 master 来查看您的情况是否已修复:

A number of problems have been resolved already - you may wish to try the latest build of master to see if your case has been fixed:

ci.appveyor/project/CharliePoole/nunit/build/3.9.0-dev-04489/artifacts

更多推荐

在类中并行运行 NUnit 测试但不与其他类测试一起运行的方法?

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

发布评论

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

>www.elefans.com

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