首页 > 解决方案 > Azure Pipelines 在运行测试之前单独构建所有项目

问题描述

我们有一个应用程序,该应用程序在自己的解决方案中隔离了许多项目,每个项目在这些解决方案中都有自己的 UnitTest 和 IntegrationTest 项目。在我们本地托管的 Azure DevOps 应用程序上发生的情况是,以下代码强制 Azure DevOps 在运行测试之前构建解决方案中的每个项目。我想做的是在初始构建上按顺序运行所有测试,或者至少缩短构建时间,因为在构建服务器上,每个构建大约需要一分钟或两分钟,这是大部分时间。由于我们让 XUnit 在说 Rider 中运行测试,它可以在一分钟内处理来自多个项目的解决方案中的所有测试。

有没有办法缩短构建时间或者这是否尽可能好?

- task: DotNetCoreCLI@2
  displayName: Unit Tests
  inputs:
    command: test

    projects: '**/*UnitTest*/*.csproj'

    arguments: '--configuration $(BuildConfiguration)'

# run integration tests
- task: DotNetCoreCLI@2
  displayName: Integration Tests
  inputs:
    command: test
    projects: '**/*IntegrationTest*/*.csproj'
    arguments: '--configuration $(BuildConfiguration)'

标签: unit-testing.net-coreazure-devopsintegration-testing

解决方案


在我们本地托管的 azure devops 应用程序上发生的情况是,以下代码将导致 Azure Devops 在运行测试之前构建解决方案中的每个项目。

对于这个问题,您可以添加--no-build参数以在测试运行时跳过项目构建。

  • --no-build

在运行之前不构建测试项目。这在文档的选项部分中列出。

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    command: test
    projects: '**/*UnitTest*/*.csproj'
    arguments: '--configuration $(BuildConfiguration) --no-build'

这里有一个类似问题的案例,你可以参考一下。


推荐阅读