azure-devops - 如何在 Azure DevOps 管道中添加单元测试

标签 azure-devops azure-pipelines vs-unit-testing-framework

构建运行良好但看不到单元测试结果 添加使用经典编辑或我的解决方案的构建管道时。

而且代码覆盖率也空白。我在解决方案中有两个项目和测试项目。单元测试任务返回结果如下:

    A total of 14 test files matched the specified pattern.
           No test is available in d:\a\1\s\src.net... 
Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
            Results File: d:\a\_temp\TestResults\VssAdministrator_fv-az686_2019-12-26_06_10_28.trx
            Attachments:
              d:\a\_temp\TestResults\d301a26b-d99f-4b4e-bbe8-c95e588ee1c5\VssAdministrator_fv-az686 2019-12-26 06_10_20.coverage
            Vstest.console.exe exited with code 0.
            **************** Completed test execution *********************
            Test results files: d:\a\_temp\TestResults\VssAdministrator_fv-az686_2019-12-26_06_10_28.trx
            No Result Found to Publish 'd:\a\_temp\TestResults\VssAdministrator_fv-az686_2019-12-26_06_10_28.trx'.
            Created test run: 1006840
            Publishing test results: 0
            Publishing test results to test run '1006840'.
            TestResults To Publish 0, Test run id:1006840
            Published test results: 0
            Publishing Attachments: 2
            Completed TestExecution Model...

而且我也从测试窗口看不到了。

测试YAML脚本如下:
steps:
- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     !**\obj\**
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

最佳答案

您的 YAML 没有任何问题,相同的定义对我来说都适用。

A total of 14 test files matched the specified pattern.

No test is available in d:\a\1\s\src.net...


根据这些错误消息,测试文件已从文件夹中识别出来,这意味着 dll 现在已经存在。但它仍然说没有可用的测试,这与vstest.console.exe 更相关。没有识别测试。
例如 , 如果您的测试项目类型是 NUnit ,您可以使用一个扩展名 NUnit 测试适配器来支持在 Visual Studio 中运行的这种测试类型。
但是,当项目发布到 VSTS 时,此扩展也无法发布,并且 VSTS 托管代理中不存在此扩展。如果没有此扩展支持,vstest.console.exe无法识别 Nunit test ,然后会提示No test is available in xxxxxxx .见 this如引用。
但是,您可以安装 nuget 包来替换该 VS 扩展的角色。
如果它的类型是 Nunit test,你必须确保在包上添加引用 NUnitNUnit3TestAdapter在您的 csproj文件:
<PackageReference Include="NUnit">
      <Version>3.12.0</Version>
    </PackageReference>
<PackageReference Include="NUnit3TestAdapter">
      <Version>3.15.1</Version>
    </PackageReference>
类似方法 tp xUnit test .

关于azure-devops - 如何在 Azure DevOps 管道中添加单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59484609/

相关文章:

azure - 如何从 Azure 发布管道配置 Jmeter 测试

azure-devops - Azure Pipeline 仅推送具有新版本的 NuGet 包

azure - 完成时使用不同参数触发相同的 Azure DevOps 管道

azure - 有什么办法可以缓存git源文件吗?

visual-studio-2012 - Visual Studio 2012 - 调用目标引发了异常。

visual-studio-2015 - 无法将共享项目添加到 Visual Studio 测试项目

azure-devops - Azure DevOps : How to manage VM agents when multiple projects deploy to the same virtual machine

azure - 为什么我的构建管道突然失败并出现代码分析错误?

azure - 如何通过 azure Devops 管道运行 AzureRM 脚本

使用 Visual Studio 测试框架进行 C++ 单元测试