azure-devops - 使用 YAML 在 VSTest 任务中重新运行失败的测试
问题描述
我想通过 YAML 在 Azure Pipelines 中重新运行失败的测试。
项目结构:
RerunTestsDemo.sln
+-- ClassLibrary1.csproj
+-- UnitTestProject1.csproj
+-- UnitTestProject2.csproj
天蓝色管道.yml:
trigger:
- automation/infra
pool: '$(AZURE_AGENT_POOL)'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/MyUnitTestProject.csproj'
- task: VisualStudioTestPlatformInstaller@1
inputs:
packageFeedSelector: 'nugetOrg'
versionSelector: 'latestStable'
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
publishRunAttachments: true
rerunFailedTests: true
rerunType: 'basedOnTestFailurePercentage'
rerunFailedThreshold: '30'
rerunMaxAttempts: '2'
env:
# All env vars correctly configured in pipeline
但它没有找到任何测试:
解决方案
请尝试以下方法,看看它是否可以工作。
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet build $(buildConfiguration)'
inputs:
projects: |
**/ClassLib1.csproj
**/ClassLib2.csproj
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'dotnet test $(buildConfiguration)'
inputs:
command: test
projects: '**/MyUnitTestProject.csproj'
arguments: '--configuration $(buildConfiguration)'
[更新]
这是一个示例作为参考:
steps:
. . .
- task: VSBuild@1
displayName: 'Build solution **\*.sln'
inputs:
solution: '$(Parameters.solution)'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
publishRunAttachments: true
rerunFailedTests: true
rerunType: 'basedOnTestFailurePercentage'
rerunFailedThreshold: '30'
rerunMaxAttempts: '2'