【问题标题】:MTM : Is there a way to find test run completion status using command line utility tcm.exeMTM:有没有办法使用命令行实用程序 tcm.exe 查找测试运行完成状态
【发布时间】:2013-12-11 21:28:45
【问题描述】:

我使用 MTM(Microsoft 测试管理器)来运行我的自动化测试用例。

我使用tcm /create 命令(从powershell 脚本触发)安排测试运行,一旦测试运行完成,我需要将trx(结果)文件复制到我的本地计算机上。所以我想等到测试运行在某种轮询机制中完成。

因此,我需要一个命令来使用 test runid 获取当前的测试运行状态。有没有办法通过这种方式获取MTM测试运行状态?

【问题讨论】:

    标签: microsoft-test-manager tcm


    【解决方案1】:

    我认为这是不可能的。 run 选项的可用开关是:

    • 删除
    • 中止
    • 导出
    • 列表
    • 创建
    • 发布

    您可以使用/list 获取的关于runs 的唯一数据是

    • 身份证
    • 标题
    • 所有者
    • 完成日期

    你可以通过运行看到这个:

    tcm run /list /planid:<plainId> /collection:<CollectionUrl> /teamproject:<TeamProject>
    

    此外,您还没有runId,因此即使可以选择获取完成状态,在您的情况下也不容易。

    所以,我认为您应该开始寻找另一种解决方案。也许TFS Api 是您所需要的。 检查这些链接:

    1. Automation test run creation using tfs api
    2. TFS 2010 API - Get Results of a Test Run

    【讨论】:

    • 我同意@Schaliasos。我需要等到几个月前测试运行完成并最终使用提到的 TFS Api 实现命令行工具的可能性。它工作得非常完美,您可以完全控制它。
    【解决方案2】:

    您实际上可以获得测试 id - 它是作为 tcm.exe run /create 命令的结果打印出来的 在 powershell 中会是这样的:

    $testRunSubmitResult = .$tcmPath run /create ......
    
    $testID = $testRunSubmitResult -match "[0-9]{1,1000}"
    
    (i excluded the error handling logic which needs to be present in order to verify that the run was submitted)
    
    after that you can do the following thing - you can export the test run with the used id, and if the test didnt finish yet, you will get and error.
    
    do
    
    {
    
        Start-Sleep -s 60
    
        $testResults = .$tcmPath run /export /id:$testID /resultsfile:$args /collection ....
    
        if(Test-Path $args[0])
    
        {
    
            break
    
        }
    
        if($testResults.GetType() -eq @("1").GetType())
    
        {
    
            if($testResults[1].Contains("Completed export"))
    
            {
    
                break
    
            }
    
        }
    
        if ($testResults.Contains("Completed export"))
    
        {
    
            break
        }
    }
    while ($True)
    

    这并不完美,因为它可能会在带有大附件(例如由视频数据收集器生成的附件)的测试运行中失败,但它可能是你们中某些人的解决方案

    或者,您也可以通过 powerscript 像这样使用 TFS API:

    Add-Type -AssemblyName "Microsoft.TeamFoundation.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    
                           "Microsoft.TeamFoundation.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    
                           "Microsoft.TeamFoundation.TestManagement.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    
    $tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection("http://tfs:8080/tfs/Collection")
    $tfs.EnsureAuthenticated()
    $testManagementService = $tfs.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
    $testManagementTeamProject = $testManagementService.GetTeamProject('Project');
    
    do
    {
        Start-Sleep -s 60
        $testRun = $testManagementTeamProject.TestRuns.Find($testId);
        if($testRun.State -eq 'Completed')
        {
            break
        }
        if($testRun.State -eq 'NeedsInvestigation')
        {
            break
        }
        if($testRun.State -eq 'Aborted')
        {
            break
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-01
      • 2021-03-18
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      • 2019-12-31
      • 1970-01-01
      相关资源
      最近更新 更多