无法通过PowerShell脚本将(某些)SpecFlow测试导入TFS?

时间:2017-10-04 11:00:35

标签: powershell tfs specflow microsoft-test-manager

我在VSTFS 2015中每晚运行一次SpecFlow测试的自动构建,该测试通过PowerShell脚本填充。大多数测试导入都没有问题,但是在大约800次测试中,大约30次无法导入。

TFS构建返回的错误是:

TF237086:无法保存工作项,因为至少有一个字段包含不允许的值。

由于这是一个脚本,这些特定测试似乎很奇怪,始终无法导入。

下面添加了脚本(大部分来自你们的互联网):



    [CmdletBinding()]

    $storage = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY\AcmeCo.Acceptance.Tests.dll"

    Write-Host "Importing tests from '$storage'"

    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite1" /syncsuite:135777
    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite2" /syncsuite:148870
    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite3" /syncsuite:135775
    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite4" /syncsuite:148872

    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite5" /syncsuite:135781
    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite6" /syncsuite:135782
    & 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TCM.exe' testcase /collection:$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI /teamproject:"AcmeCo" /import /storage:$storage /category:"SomeSuite7" /syncsuite:148869

    Write-Host "Tests imported"

    Write-Host "Updating test plans"
    [Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')
    [Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.TestManagement.Client')
    [Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Build.Client')

    # Find all test plans using this build definition
    $tpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)
    $tcm = $tpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
    $buildServer = $tpc.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
    $teamProject = $buildServer.GetBuild($Env:BUILD_BUILDURI);
    $testProject = $tcm.GetTeamProject($teamProject.TeamProject);
    $testPlans = $testProject.TestPlans.Query("SELECT * FROM TestPlan")

    $matchingTestPlans = @()
    foreach($testPlan in $testPlans)
    {
        Write-Host "The current Test Plan build definition is: '$testPlan.BuildFilter.AreaPath'"

        if($testPlan.BuildFilter.AreaPath -contains 'AcmeCo Test Plan')
        {
            $matchingTestPlans += $testPlan
        }
    }

    # Update test plans with latest build
    if($matchingTestPlans)
    {
        Write-Host "Updating test plans using '$Env:BUILD_BUILDDEFINITIONNAME' to '$Env:BUILD_BUILDURI' ($($matchingTestPlans.count) matching test plans)"

        foreach ($matchingTestPlan in $matchingTestPlans) {
            $matchingTestPlan.BuildUri = $Env:BUILD_BUILDURI
            $matchingTestPlan.Save()
        }

        Write-Host "Test plans updated"
    }
    else
    {
        Write-Warning "Found no test plans to update."
    }

关于为什么某些测试无法导入,或者之前有人遇到此问题的任何想法?

1 个答案:

答案 0 :(得分:1)

查找/缩小错误的最佳方法是在MTM中手动创建失败的自动化测试用例。

实际上要创建一个测试用例,只有" 标题"价值是必要的。但是,您还应该双重确认测试用例中的字段是否存在错误的默认值。因为至少有一个字段包含不允许的值将导致此错误。这意味着这可能是测试用例模板错误。

更多解决问题的方法请看一下类似的问题:How to troubleshoot TFS error TF237086 "The work item cannot be saved..."