在Azure DevOps管道中运行NUnit测试

7

这是可能的吗?(看起来不是。不支持NUnit吗?我应该使用什么代替?)

这是我的测试项目。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\TheProjectToBeTested\TheProjectToBeTested.csproj" />
  </ItemGroup>

</Project>

这里是我的azure-pipelines.yml文件。

pool: 'TFSBuild'

variables:
# The web app will not build because it is netcore3.1 and the server only supports netcore3.0.
  solution: '**/*Build.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

# I added this and I don't undertand it.
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     **\$(BuildConfiguration)\**\*test*.dll
     !**\*Microsoft.VisualStudio.TestPlatform*
     !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'

然而测试并未被执行。
##[section]Starting: VSTest
==============================================================================
Task         : Visual Studio Test
Description  : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version      : 2.153.9
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/test/vstest
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : E:\TFS\8\s
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation.
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Test selector : Test assemblies
Test assemblies : **\Release\*test*.dll,**\Release\**\*test*.dll,!**\*Microsoft.VisualStudio.TestPlatform*,!**\obj\**
Test filter criteria : null
Search folder : E:\TFS\8\s
Run settings file : E:\TFS\8\s
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
Rerun failed tests: false
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation.
========================================================
======================================================
[command]"E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" @E:\TFS\_temp\126341f1-33c9-11eb-a545-b3a68600e11b.txt
Microsoft (R) Test Execution Command Line Tool Version 16.3.0-preview-20190715-02
Copyright (c) Microsoft Corporation.  All rights reserved.

vstest.console.exe 
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\TheProjectToBeTested.Test.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CommunicationUtilities.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CoreUtilities.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CrossPlatEngine.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.PlatformAbstractions.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.Utilities.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\NUnit3.TestAdapter.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\testhost.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
/logger:"trx"
/TestAdapterPath:"E:\TFS\8\s"
Starting test execution, please wait...
Test run will use DLL(s) built for framework .NETFramework,Version=v4.0 and platform X86. Following DLL(s) do not match framework/platform settings.
TheProjectToBeTested.Test.dll is built for Framework .NETCoreApp,Version=v3.0 and Platform AnyCPU.
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CoreUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CrossPlatEngine.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.PlatformAbstractions.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Microsoft.TestPlatform.Utilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
NUnit3.TestAdapter.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
testhost.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.

No test is available in E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\TheProjectToBeTested.Test.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CommunicationUtilities.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CoreUtilities.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CrossPlatEngine.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.PlatformAbstractions.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.Utilities.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\NUnit3.TestAdapter.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\testhost.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CrossPlatEngine.resources.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Results File: E:\TFS\8\s\TestResults\TFSBUILD$_TFSBUILD_2020-12-01_11_33_48.trx

No Result Found to Publish 'E:\TFS\8\s\TestResults\TFSBUILD$_TFSBUILD_2020-12-01_11_33_48.trx'.
##[section]Async Command Start: Publish test results
##[section]Async Command End: Publish test results
##[section]Finishing: VSTest

不知道你最近的情况。只是想确认以下答案对你是否有帮助?或者如果你有任何疑虑,请在下面留言。 - Hugh Lin
4个回答

10
请改用dotnet命令,而不是使用VSTest运行单元测试:

如果您的代码库中有测试项目,则可以使用.NET Core任务来运行单元测试,使用MSTest、xUnit和NUnit等测试框架。

steps:
# ...
# do this after other tasks such as building
- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

1
@RichardBarraclough 首先不要添加关键字“steps”,其次您必须根据您的解决方案设置“projects”。它可以像上面那样,但不一定。 - Krzysztof Madej
模板很好,但它只能与MSTest配合使用,而不能与NUnit或xUnit配合使用。我尝试配置VSTest来运行NUnit测试,但每次都是相同的情况-无法找到测试。这很奇怪,因为如果我本地运行vstest.console.exe就没问题。 - Krzysztof Madej
1
似乎VS*任务是垃圾,最好使用“dotnet”或“PowerShell”任务。 - Richard Barraclough
我认为这不值得花太多时间去配置。如果没有明确的路径来实现这一点,而另一方面你可以使用一些简单有效的东西,并且它可以在Linux和Windows主机代理上工作(并且你应该观察到在Linux上更快的运行),那么你可以从中受益。当然,如果你在Linux上托管你的应用程序,我建议使用Linux主机代理。 - Krzysztof Madej
无法运行 DLL 文件(预编译) - NiKiZe
显示剩余5条评论

2
在Azure DevOps管道中运行NUnit测试。
为了使用Visual Studio Test任务测试.Net Core dll,请尝试添加Visual Studio Test任务的以下附加设置:
1. vstest.console.exe路径:E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform。 2. 其他控制台选项:/framework:".NETCoreApp,Version=v3.0"。

这些选项对我来说失败了:2021-06-06T18:22:04.3534084Z 描述:使用Visual Studio测试(VsTest)运行单元和功能测试(Selenium,Appium,Coded UI测试等)。具有Visual Studio测试适配器的测试框架,如MsTest,xUnit,NUnit,Chutzpah(用于使用QUnit,Mocha和Jasmine的JavaScript测试)等,都可以运行。使用此任务(版本2),可以在多个代理上分发测试。 2021-06-06T18:22:04.3534840Z 版本:2.170.1 ...snip... 2021-06-06T18:22:06.4779338Z ##[error] VsTest任务失败。 - JeffFerguson
这些选项可能对我失败了,因为我的单元测试是.NET 5.0。我可以尝试不同的控制台选项。 - JeffFerguson

0

你可能在项目中缺少NUnit3TestAdapter包

<?xml version="1.0" encoding="utf-8"?>
<packages>
   <package id="NUnit" version="3.10.1" targetFramework="net45" />
   <package id="NUnit3TestAdapter" version="4.1.0" targetFramework="net45" />
</packages>

在添加了包之后,此任务运行了所有的nunit测试。
- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

0

如果您有一个 .net core 应用程序,那么使用 DotNetCoreCLI@2 命令和 test 命令的答案是正确的。

然而,如果您正在使用框架并且不想使用 VSTest 或者确实必须使用 nunit,那么还有另一种方法可以使其工作。

您可以使用带有 nunit 的 docker 容器来进行管道操作。您可以使用 这里的代码,这是一个已添加了 nunit 的 mono 镜像。Azure Devops 的要求是没有入口点,因此您需要使用自己的副本而不包括最后一行。

一旦您拥有了容器,就可以在其中运行您的管道并使用 bash 命令块

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: '/nunit/nunit3-console.exe **/*Tests/*.csproj --configuration $(buildConfiguration)'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接