visual-studio-2019 - 即使通过 UI 选择该选项,单元测试也不会并行运行

标签 visual-studio-2019 mstest

这似乎是一个非常基本的问题,但 Microsoft 在为多个版本的 Visual Studio 并行运行单元测试时遇到了问题。我们发现以前有效的唯一方法(同时使用 .runsettings 和已弃用的 .testsettings 文件)似乎不再有效,可能是由于 MSTest v2。 .runsettings 文件 ( https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019 ) 的最新文档没有帮助,因为其中的设置没有效果(至少在我们的用例中)。

最佳答案

经过多次谷歌搜索、链接、阅读和测试,我终于在本页的链接中找到了答案:https://marketplace.visualstudio.com/items?itemName=OsirisTerje.Runsettings-19151 :

<RunSettings>
<!-- MSTest adapter -->  
  <MSTest>
    <Parallelize>
      <Workers>4</Workers>
      <Scope>ClassLevel</Scope>
    </Parallelize>
  </MSTest>
</RunSettings>

由于某种原因,这似乎没有进入文档,但这一更改最终触发了 VS2019 中的并行 MSTEST 单元测试。

更新:

我找到了一个更好的链接:https://devblogs.microsoft.com/devops/mstest-v2-in-assembly-parallel-test-execution/ 这表明您还可以设置 <Scope>MethodLevelCustom ,您还可以添加如下的程序集属性

[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.ClassLevel)]

关于visual-studio-2019 - 即使通过 UI 选择该选项,单元测试也不会并行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62199785/

相关文章:

c# - TestContext.DataRow ["MyColumnName"的替代品是什么]

azure - 无法从 Visual Studio 2019 登录 Azure 帐户

c++ - 确定如何定义类型

c# - 无法在 Visual Studio 2019 中搜索 NuGet 包

asp.net - 针对 ASP.NET Web 服务运行自动生成的测试时,某些测试失败并返回 "the communication channel with asp.net could not be configured"

c# - MSTest:CS0117 'Assert' 不包含 'ThrowsException' 的定义

visual-studio - VSTS + Visual Studio 测试 : Add additional logs to test output

visual-studio-2008 - VS 2008/MSTest - 如何运行所有测试的子集?

Visual Studio 2019 中的 Git 日志历史记录

sqlite - 无法使用 EF6 让 SQLite 在 VS2019 中工作