【问题标题】:Azure pipeline not running NUnit testsAzure 管道未运行 NUnit 测试
【发布时间】:2019-09-10 13:23:37
【问题描述】:

刚刚被介绍到 Azure 管道。我的项目是一个 .NET 项目并与 Azure 链接,但在集成之前没有运行我的单元测试(因此即使测试失败也会集成所有内容)

我的 .yaml 文件是:

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

我的单元测试位于名为MyProjectTests 的项目下的解决方案和名为ProjectTests.cs 的文件中。谁能告诉我需要添加到我的 yaml 文件中的内容(或一般情况下?)才能让这些文件运行?我自己对此进行了调查,似乎找不到解决方案,我想避免因尝试运行单元测试失败而堵塞我的提交历史。

非常感谢。

更新:

我已通过添加以下内容进行修复:

- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

【问题讨论】:

  • 这里只是构建,没有运行测试的步骤。
  • 嗨 @davidG 是的,我知道 - 我想添加一个步骤来运行测试,但不确定语法是否正确?
  • 嗯,你可以像 build 一样做同样的事情,但改用 test
  • 生成示例 yaml 文件的最简单方法是让 Azure DevOps 为您完成。使用 UI 创建带有测试的基本管道并检查 yam lit 为您提供的结果。
  • @davidG 所以像script: dotnet test --configuration $(buildConfiguration)

标签: c# azure


【解决方案1】:

给你。

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: 'PathToTestProject/TestProject.csproj'
    arguments: '--configuration Debug'

当然,您可以选择您喜欢的任何配置。并且 displayName 是可选的。如果您的任何测试失败,管道将中止后续步骤。

【讨论】:

  • 非常感谢@RobReagan,对你很有帮助。我收到了这个错误:Unexpected value 'task'" 并且构建失败了?
  • 以及 displayName 和输入的意外值 :(
  • @juemura7 糟糕,我忘记了连字符。我已将其添加到答案中。您能否将其标记为将来可能想知道此主题的其他人的答案?谢谢!
  • 谢谢罗伯!但它实际上没有用 - 我使用了另一个解决方案并更新了我的原始帖子:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 2022-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多