简体   繁体   English

MSTest v2 有序测试

[英]MSTest v2 Ordered Tests

I am using Visual Studio 2017 Enterprise and MSTest V2.我正在使用 Visual Studio 2017 Enterprise 和 MSTest V2。 My solution has multiple Unit Test projects.我的解决方案有多个单元测试项目。 In one project, I have unit tests that are testing the loading of resources from the installation directory.在一个项目中,我有单元测试来测试从安装目录加载资源。 Most test that the resources are loaded correctly, but some delete the resource to confirm that this is handled correctly as well.大多数测试资源是否正确加载,但有些删除资源以确认这也被正确处理。

在此处输入图片说明

The issue that I am having is that the tests run in parallel.我遇到的问题是测试并行运行。 Therefore, the tests that remove the resources do this at the same time the tests that are loading the resources are running, and I get failed tests.因此,删除资源的测试在加载资源的测试正在运行的同时执行此操作,并且我得到了失败的测试。

I realize I can resolve this by updating my code to send the directory to search, or by running one set of tests and then the next, but I would prefer being able to run all tests at once.我意识到我可以通过更新我的代码以发送目录进行搜索来解决这个问题,或者通过运行一组测试然后再运行下一组来解决这个问题,但我更希望能够一次运行所有测试。 It sounds like MSTest v2 is supposed to run sequentially unless otherwise directed to run in parallel, but on my system, this is demonstrably false.听起来 MSTest v2 应该按顺序运行,除非另有指示并行运行,但在我的系统上,这显然是错误的。 It also appears that Ordered Test does not work with v2.似乎 Ordered Test 也不适用于 v2。 Is there a way to get MSTest V2 to run sequentially?有没有办法让 MSTest V2 依次运行?

  1. MStest v2 will not support orderedtests issue MStest v2 将不支持orderedtests问题
  2. you may have set the parallelization scope in testsettings file or Assembly file https://www.meziantou.net/mstest-v2-execute-tests-in-parallel.htm If you remove that it will run sequentially您可能已经在 testsettings 文件或程序集文件https://www.meziantou.net/mstest-v2-execute-tests-in-parallel.htm 中设置了并行化范围如果您删除它,它将按顺序运行

I would say that you can create a flag and update that from dependent test, check for the flag status before cleaning up resource.我会说你可以创建一个标志并从依赖测试更新它,在清理资源之前检查标志状态。 may be a dictionary of testname and status, once its done, execute this test or wait for that test to complete.可能是 testname 和 status 的字典,一旦完成,执行此测试或等待该测试完成。 you can implement a custom logic for that.您可以为此实现自定义逻辑。

要使测试按顺序运行,请在 .runsettings 文件中将 MaxCpuCount 设置为 1,有关详细信息,请参阅: 使用 .runsettings 文件配置单元测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM