【问题标题】:How to have both xUnit and NUnit in a solution built in Azure DevOps Pipelines?如何在 Azure DevOps Pipelines 中构建的解决方案中同时拥有 xUnit 和 NUnit?
【发布时间】:2020-09-22 20:25:43
【问题描述】:

我有一个 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

当我运行它时,我的管道失败并显示以下错误消息:

调用执行程序“executor://nunit3testexecutor/”时发生异常:选择表达式中第 29 位出现意外单词“类别”。

我很确定会发生这种情况,因为 NUnit 正在被使用并且它不理解 Category 过滤器术语。 (NUnit 期望使用 TestCategory 代替)

我尝试通过这种方式让管道不接收 NUnit 项目(称为“EndToEnd”):

--filter FullyQualifiedName!~EndToEnd&Category!=Integration'

但这不起作用,我收到相同的错误消息。

如何让 Azure DevOps Pipelines 在此步骤中仅在我的 xUnit 项目中运行测试,并且不会因为 NUnit 项目的存在而失败?

【问题讨论】:

  • 有什么理由不用不同的任务来运行不同的项目?只需将项目名称作为命令行参数。
  • 天啊@JonSkeet!对不起。忍不住 :) 不确定我是否遵循。是的,我正在考虑为 UT 迈出一步,为 E2E 迈出另一步,但它是多个单元测试项目和一个 E2E 项目。试图弄清楚如何从 UT 步骤中排除 E2E。
  • 看起来我已经破解了它。我的 UT 项目都称为 Foo.Tests.csproj,但我的 E2E 项目仅称为 EndToEnd。我将此行添加到步骤中并且它有效:projects: '**/*.Tests.csproj'。我认为更好的解决方案可能是:projects: !'**/*.EndToEnd.csproj'

标签: c# azure-devops nunit xunit azure-devops-pipelines


【解决方案1】:

您可以使用projects 选择项目。我对此解决方案进行了测试,它可以工作:

variables:
  buildConfiguration: 'Release'
  rootDirectory: '$(Build.SourcesDirectory)/stackoverflow/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)'

【讨论】:

    猜你喜欢
    • 2020-04-15
    • 1970-01-01
    • 2019-10-26
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    相关资源
    最近更新 更多