这可以通过 TFS API 实现。此 PowerShell 脚本向您展示了如何执行此操作(请参阅: https: //blogs.msdn.microsoft.com/gautamg/2012/01/01/how-to-associate-automation-programmatically/以供参考)。
# Get TC
$tfsTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TPC_URL)
$tms = $tfsTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$tp = $tms.GetTeamProject($TP_NAME)
$tc = $tp.TestCases.Find($tcId)
# Compute Automation Guid
$sha1Crypto = new-object System.Security.Cryptography.SHA1CryptoServiceProvider
[Byte[]] $bytes = New-Object Byte[] 16
[Array]::Copy($sha1Crypto.ComputeHash([System.Text.Encoding]::Unicode.GetBytes($testName)), $bytes, $bytes.Length)
# Create association
$tc.Implementation = $tp.CreateTmiTestImplementation($testName, $AUTOMATION_TYPE, $AUTOMATION_STORAGE_NAME, $automationGuid)
$tc.Save()
$automationGuid = New-Object -TypeName Guid -ArgumentList @(,$bytes)
Run Code Online (Sandbox Code Playgroud)
但您将无法将执行与 TFS 中的测试用例关联起来。
测试必须使用 MSTest V1 运行,以将结果记录为要通过 TCM.exe 在 TFS 中发布的有效 TRX。即使使用 vstest.console.exe 和 TRX 记录器选项,TCM.exe 也无法理解 xml 结果。
参考:http ://bugsareinthegaps.com/uploading-automated-test-results-to-mtm-made-easy/