【问题标题】:Failing to Import (some) SpecFlow Tests to TFS via PowerShell script?无法通过 PowerShell 脚本将(某些)SpecFlow 测试导入 TFS?
【发布时间】:2018-03-15 17:58:33
【问题描述】:

我有一个用于在 VSTFS 2015 中夜间运行的 SpecFlow 测试的自动构建,它通过 PowerShell 脚本填充。大多数测试导入没有问题,但在大约 800 个测试中,大约 30 个根本无法导入。

TFS 构建返回的错误是:

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

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

脚本添加在下面(大部分来自ye olde interweb):



    [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."
    }

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

【问题讨论】:

    标签: powershell tfs specflow microsoft-test-manager


    【解决方案1】:

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

    实际上要创建一个测试用例,只需要“Title”值。但是,您还应该再次确认测试用例中是否存在错误的字段默认值。因为至少一个字段包含一个不允许的值会导致这个错误。这意味着这可能是一个测试用例模板错误。

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

    【讨论】:

    • 感谢您的意见...我已尝试对测试进行更改,但看不出与其他成功导入的测试有任何显着差异,包括具有相同“功能”文件的测试。糊涂了。
    • 所以。鉴于“标题”是唯一需要的主要字段并且测试是自动化的,我查看了与其他测试相比的测试长度。事实证明,Title 字段很可能存在字符限制。
    • 要么,要么存在字符编码问题。解决这两个因素可确保成功的测试导入。哈扎!
    猜你喜欢
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    相关资源
    最近更新 更多