0

我有一个 Azure DevOps 发布管道设置来根据此设置运行我的测试:

https://docs.microsoft.com/en-us/azure/devops/test/run-automated-tests-from-test-hub?view=azure-devops

我的类文件包含一个单元测试,其中包含 4 个测试用例,方式如下:

[TestCase("test1", "arg1", "arg2")]
[TestCase("test2", "arg1", "arg2")]
[TestCase("test3", "arg1", "arg2")]
[TestCase("test4", "arg1", "arg2")]
public void Test(string name, string arg1, string arg2)
{
    TestStuff();
}

当我运行测试时,会创建一个新版本并成功运行测试,但是仅找到 4 个测试中的 3 个。test2由于某种原因找不到,只会被跳过。从日志中我可以看到总共发现了 146 个测试,这是准确的,但只有 3 个被“发现”

2020-08-19T23:41:28.3146168Z Number of testcases discovered : 146
2020-08-19T23:41:28.3166614Z ##[debug]PERF: DiscoverTests:AddTestCases: took 0.005 ms
2020-08-19T23:41:28.3290518Z Discovered tests 146 from sources
2020-08-19T23:41:28.3291189Z 
=================================================================
2020-08-19T23:41:28.3291959Z ##[debug]DiscoverTests.PerformDiscovery : Test Discovery completed.
2020-08-19T23:41:28.3295732Z ##[debug]PERF WARNING: DiscoverTests.PerformDiscovery: took 11963.8108 ms
2020-08-19T23:41:28.3607538Z [RunStatistics]This execution slice with id '3', received '4' testcases to execute out of which '3' is discovered.

只有3个是什么意思discovered

如果我尝试自己运行该测试,那么整个事情都会失败

Microsoft.VisualStudio.TestService.VstestAdapter.TestsNotFoundException:在测试机器上未找到与源筛选条件匹配的测试程序集,或未发现与测试筛选条件匹配的测试。验证机器上是否存在测试组件并且测试过滤器标准是否正确。

我已经通过 VS (2019) 验证了测试已正确关联到测试用例,并且其他 3 个测试运行良好,它只是 1 个由于某种原因找不到的测试。

4

1 回答 1

0

这个问题原来是单元测试和测试用例之间的链接问题。我验证了现有的关联是正确的,但我最终得到了:

  1. 在 Azure DevOps 测试用例详细信息中删除了Associated Automation
  2. 在 VS2019 中,我将单元测试重新关联到测试用例

我再次运行了测试计划,那时所有的测试用例都找到了。

于 2020-08-25T18:04:06.377 回答