Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops 如何在Azure DevOps管道中添加单元测试_Azure Devops_Azure Pipelines_Vs Unit Testing Framework - Fatal编程技术网

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

Azure devops 如何在Azure DevOps管道中添加单元测试,azure-devops,azure-pipelines,vs-unit-testing-framework,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 a

该构建运行良好,但在添加使用经典编辑或“我的解决方案”的构建管道时,无法看到单元测试结果

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

    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...
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... 
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...
steps:
- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     !**\obj\**
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

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

共有14个测试文件与指定的模式匹配

d:\a\1\s\src.net中没有可用的测试

根据这些错误消息,测试文件已从文件夹中标识出来,这意味着DLL现在已经存在。但是它仍然说没有可用的测试,这与
vstest更为相关。console.exe
没有识别测试

例如,如果测试项目类型为
NUnit
,则可以使用一个扩展名NUnit测试适配器来支持在visual studio中运行的此测试类型

但是,当项目发布到VSTS中时,此扩展也无法发布,并且此扩展不存在于VSTS托管代理中。如果没有此扩展支持,
vstest.console.exe
无法识别
Nunit测试
,那么它将提示消息,如xxxxxxx中没有可用的测试。参见

但是,您可以安装nuget软件包来替换该VS扩展的角色

如果其类型为Nunit test,则必须确保在
csproj
文件中添加对包
Nunit
NUnit3TestAdapter
的引用:

<PackageReference Include="NUnit">
      <Version>3.12.0</Version>
    </PackageReference>
<PackageReference Include="NUnit3TestAdapter">
      <Version>3.15.1</Version>
    </PackageReference>

3.12.0
3.15.1

类似的方法tp
xUnit test

包已经添加到我的nuget包配置文件中,你的意思是我还必须在我的csproj文件中添加配置,以帮助管道构建识别测试项目吗?配置如下:Hi@Merlin Liang,在我运行管道之后,另一个信息将显示:确保测试发现者和执行者已注册,平台和框架版本设置正确,然后重试。我的项目是MSTestproject@element87631.对于最新的评论,这行代码表明我们的系统没有检测出测试/框架版本等脚本。所以它可以让你确保它们存在。2.您在第一条评论中提到的脚本是否在配置中?根据我的经验,此systax
位于csproj
。如果你不介意的话,你能给我看一个你们项目的样品吗?或者只与我共享您的
csproj
?关于2,它是csproj文件的一部分。我只是做了一个测试解决方案,并在azure devops上添加了一个管道,仍然存在相同的错误。您可以找到代码@Merlin Liang-MSFT@element8763,我看到mstest使用的是.net内核。因此,请尝试使用dotnetrestore/build/test来编译项目。这是我基于代码运行的结果:(忽略发布任务,我没有在其中指定参数,但它的失败不会影响测试)