我在项目中有几个相互依赖的单元测试。在一个测试运行后,我将捕获输出,等待它在另一个系统中同步并使用第一个测试的输出执行另一个测试。我正在尝试使用天蓝色管道来实现这一目标。我创建了 3 个代理作业 - 在作业 A 中,我正在运行 Unit Test1 并创建一个输出变量,该变量传递给作业 C 中的一个变量,作业 B 是一个无代理服务器,在这两个代理之间延迟 1 分钟。我已经使用 overrideTestrunParameters: '-sauce2 $(sauce5)' 来覆盖第二个测试的参数,但是在将参数传递给第二个代理任务时出现以下错误。
[警告]无法解析覆盖运行参数字符串:-sauce2 碎番茄
[错误]SetupPhase.Run:更新运行设置期间发生异常:System.FormatException:覆盖测试运行参数时遇到错误。请检查提供的测试运行参数。
在 Microsoft.VisualStudio.TestService.SettingsManager.OverrideParamsSettingsProcessor.GetOverrideParameters(String overrdeParametersString) 在 Microsoft.VisualStudio.TestService.SettingsManager.OverrideParamsSettingsProcessor.UpdateSettingsWithParameters(XDocument 设置) 在 Microsoft.VisualStudio.TestService.SettingsManager.CommonSettingsManager.UpdateCommonSettings(InputDataContract inputDataContract, SettingsModifier settingsModifier ) 在 Microsoft.VisualStudio.TestService.SettingsManager.SettingsManager.UpdateSettingsAsRequired(InputDataContract inputDataContract) 在 MS.VS.TestService.VstestConsoleAdapter.SetupPhase.Run(VstestConsoleRunContext testRunContext, CancellationToken cancelToken)
[错误]设置更新失败并出现错误:覆盖测试运行参数时遇到错误。请检查提供的测试运行参数。
测试运行参数:
<RunSettings>
<TestRunParameters>
<Parameter name="sauce" value="chilly" />
<Parameter name="sauce1" value="chilly1" />
<Parameter name="sauce2" value="chilly2" />
</TestRunParameters>
单元测试:
[Test]
public void UnitTest1()
{
string sauce = TestContext.Parameters["sauce"];
string sauce1 = TestContext.Parameters["sauce1"];
TestContext.Progress.WriteLine(sauce);
TestContext.Progress.WriteLine(sauce1);
//creating outpute variable in azure
TestContext.Progress.WriteLine("##vso[task.setvariable variable=sauce4;Secret=false;isOutput=true;]crushed tomatoes");
}
[Test]
public void UnitTest2()
{
string sauce2 = TestContext.Parameters["sauce2"];
TestContext.Progress.WriteLine($"sauce2: {sauce2}");
}
Azure.yaml 管道:
jobs:
- job: A
pool:
name: New Agent Pool
demands:
- msbuild
- visualstudio
- vstest
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
sauce: 'tomato'
sauce1: 'pepper'
steps:
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
displayName: 'Unit Test1'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*Test*.dll
!**\obj\**
testFiltercriteria: 'Name=UnitTest1'
runSettingsFile: SeleniumTest.ABC/Test.runsettings
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
overrideTestrunParameters: '-sauce $(sauce)'
name: 'OutputVar'
- job: B
dependsOn:
- A
pool: server
steps:
- task: Delay@1
inputs:
delayForMinutes: '1'
- job: C
dependsOn:
- A
- B
pool:
name: New Agent Pool
demands:
- msbuild
- visualstudio
- vstest
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
sauce2: $[dependencies.A.outputs['outputVar.sauce4']]
steps:
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host run time value
Write-Host sauce2 = $(sauce2)
- task: VSTest@2
displayName: 'Unit Test2'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*Test*.dll
!**\obj\**
testFiltercriteria: 'Name=UnitTest2'
runSettingsFile: SeleniumTest.ABC/Test.runsettings
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
overrideTestrunParameters: '-sauce2 $(sauce2)'
condition: succeededOrFailed()
我可以看到在 Powershell 任务中打印了新的运行时参数,但在 VS 测试任务中失败了。有人可以建议我如何在 VSTest 任务中捕获运行时变量并将其传递给 Azure 管道中的另一个 VSTest 任务。