如何在 Azure DevOps Pipelines 中构建的解决方案中同时拥有 xUnit 和 NUnit?
How to have both xUnit and NUnit in a solution built in Azure DevOps Pipelines?
我有一个 C# 解决方案,其中有几个使用 xUnit 的单元测试项目和一个使用 NUnit 的“端到端”测试项目。 (这是故意的,很好,所以我很感激不要试图说服我放弃一个,谢谢)
我使用 Azure DevOps Pipeline 来构建、测试和打包我的解决方案。这是我目前的测试步骤(来自 azure-pipelines.yml):
- task: DotNetCoreCLI@2
displayName: 'Run tests in solution'
inputs:
command: 'test'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage" --filter Category!=Integration'
publishTestResults: true
当我 运行 这时,我的管道失败并显示此错误消息:
An exception occurred while invoking executor 'executor://nunit3testexecutor/': Unexpected Word 'Category' at position 29 in selection expression.
我很确定发生这种情况是因为 NUnit 正在被拾取并且它不理解 Category
过滤器术语。 (NUnit 期望术语 TestCategory
代替)
我尝试通过这种方式让管道不接收 NUnit 项目(称为“EndToEnd”):
--filter FullyQualifiedName!~EndToEnd&Category!=Integration'
但这不起作用,我收到了相同的错误消息。
如何让 Azure DevOps Pipelines 在此步骤中仅 运行 我的 xUnit 项目中的测试并且不会因为 NUnit 项目的存在而失败?
您可以使用projects
选择项目。我针对此解决方案对此进行了测试并且它有效:
variables:
buildConfiguration: 'Release'
rootDirectory: '$(Build.SourcesDirectory)/Whosebug/69-nunit-and-xunit'
steps:
- task: DotNetCoreCLI@2
displayName: Restore nuget packages
inputs:
command: restore
projects: '**/*.csproj'
workingDirectory: $(rootDirectory)
- task: DotNetCoreCLI@2
displayName: Test xUnit
inputs:
command: test
projects: '$(rootDirectory)/**/*XUnit.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Test NUnit
inputs:
command: test
projects: '$(rootDirectory)/**/*NUnit.csproj'
arguments: '--configuration $(buildConfiguration)'
我有一个 C# 解决方案,其中有几个使用 xUnit 的单元测试项目和一个使用 NUnit 的“端到端”测试项目。 (这是故意的,很好,所以我很感激不要试图说服我放弃一个,谢谢)
我使用 Azure DevOps Pipeline 来构建、测试和打包我的解决方案。这是我目前的测试步骤(来自 azure-pipelines.yml):
- task: DotNetCoreCLI@2
displayName: 'Run tests in solution'
inputs:
command: 'test'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage" --filter Category!=Integration'
publishTestResults: true
当我 运行 这时,我的管道失败并显示此错误消息:
An exception occurred while invoking executor 'executor://nunit3testexecutor/': Unexpected Word 'Category' at position 29 in selection expression.
我很确定发生这种情况是因为 NUnit 正在被拾取并且它不理解 Category
过滤器术语。 (NUnit 期望术语 TestCategory
代替)
我尝试通过这种方式让管道不接收 NUnit 项目(称为“EndToEnd”):
--filter FullyQualifiedName!~EndToEnd&Category!=Integration'
但这不起作用,我收到了相同的错误消息。
如何让 Azure DevOps Pipelines 在此步骤中仅 运行 我的 xUnit 项目中的测试并且不会因为 NUnit 项目的存在而失败?
您可以使用projects
选择项目。我针对此解决方案对此进行了测试并且它有效:
variables:
buildConfiguration: 'Release'
rootDirectory: '$(Build.SourcesDirectory)/Whosebug/69-nunit-and-xunit'
steps:
- task: DotNetCoreCLI@2
displayName: Restore nuget packages
inputs:
command: restore
projects: '**/*.csproj'
workingDirectory: $(rootDirectory)
- task: DotNetCoreCLI@2
displayName: Test xUnit
inputs:
command: test
projects: '$(rootDirectory)/**/*XUnit.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Test NUnit
inputs:
command: test
projects: '$(rootDirectory)/**/*NUnit.csproj'
arguments: '--configuration $(buildConfiguration)'