我在项目中有几个相互依赖的单元测试。运行一个测试后,我将捕获输出,等待它在另一个系统中同步,并使用第一个测试的输出执行另一个测试。我正在尝试使用azure管道实现这一目标。我创建了3个代理作业-在作业A中,我正在运行Unit Test1并创建一个输出变量,该变量将传递给作业C中的变量,作业B是一个没有代理的服务器,要在这两个代理之间延迟1分钟。我已经使用了overrideTestrunParameters:'-sauce2 $(sauce5)'来覆盖第二次测试的参数,但是在将参数传递给第二个代理任务时却报错了。
在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 cancellingToken)
TestRunParameters:
<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 Task中捕获运行时变量,以及如何在Azure管道中传递给另一个VSTest Task。
答案 0 :(得分:2)
输出变量已成功从作业A传递到作业C,因为powershell任务可以打印出新变量$(source2)
。
问题来自作业C中vstest任务的overrideTestrunParameters: '-sauce2 $(sauce2)'
。$(sauce2)
的评估结果为crushed tomatoes
,但不带引号“”。
请尝试将$(sauce2)
用双引号引起来:
overrideTestrunParameters: '-sauce2 "$(sauce2)"'