【问题标题】:TFS 2012 API : Unable to add Test Point to Test runTFS 2012 API:无法将测试点添加到测试运行
【发布时间】:2013-06-27 02:50:59
【问题描述】:

我正在尝试使用 TFS API 从单独运行的自动化中更新测试结果。我已经尝试过这里其他问题的建议(特别是How to create a test run and result using the Team Foundation Server API?)以及其他地方的搜索。无论我尝试什么,我都会遇到同样的问题:每次我尝试将测试点添加到测试运行时,我都会收到错误 -

Microsoft.TeamFoundation.TestManagement.Client.TestManagementInvalidOperationException: This test run cannot be created with the test points.

测试点是使用 WIQL 从 TFS 检索的,我会检查每个测试点以确保在尝试添加测试计划、测试套件和测试配置之前它是正确的。

如果没有测试点,我无法保存测试运行。

示例代码(我已经经历了如此多的尝试,以至于我的代码现在已经凌乱不堪了)

    public void UpdateTests(TestSuiteRun suiteRun)
    {


        this.Config = FindConfig(suiteRun.Description);
        this.Suite = FindSuite(suiteRun.Name); 
        this.Plan = Suite.Plan;
        this.Points = FindPoints(this.Suite.Id, this.Config.Id);
        ITestCaseCollection testCases = Suite.AllTestCases;
        this.Run = TeamProject.TestRuns.Create();
        ConfigureTestRun(); // failing here

        this.Result = CreateRunResults();

        this.Iteration = CreateSingleIteration(suiteRun.Description);
        {
            UpdateResultsForScenario(scen);
        }


     }

以及配置测试运行的方法:

    private void ConfigureTestRun()
    {
        this.Run.DateStarted = DateTime.Now;
        this.Run.DateCompleted = DateTime.Now;
        // find the points that correspond to test cases in the run suite
        foreach (ITestPoint point in this.Points)
        {
            if (point.TestCaseExists && point.Plan.Id == this.Plan.Id && point.ConfigurationId == this.Config.Id)
            {
                this.Run.AddTestPoint(point, this.CurrentUser); // fails with InvalidOperationException
            }
        }

        this.Run.Save();
    }

我能够连接到 TFS 并检索我需要的所有数据,但是在新的测试运行中添加测试点让我发疯。

我做错了什么?

【问题讨论】:

  • “保存”返回什么,如果是Bool,结果是什么?
  • @DaveShaw 我没有进入“保存” - 例程在 Run.AddTestPoint() 上失败。

标签: tfs-sdk


【解决方案1】:

经过大量疯狂的实验,并用头撞墙,我找到了答案。

对于那些好奇的人,这是它的工作原理:

  • 如果我使用 ITestManagementService.TestRuns.Create(); 我可以添加测试用例,但是 不是测试点。

  • 如果我使用 ITestPlan.CreateTestRun(isAutomated);我可以添加测试点但不能 测试用例。

为了让它工作,我做了很多复杂的事情——我现在已经清理了很多乱七八糟的东西,并让我的应用程序正确地向 TFS 报告测试结果。

我或多或少地使用了Jason Prickett's blog 所描述的假构建。

我发现的一件事是我无法将运行定义为自动运行,因为我的环境中没有测试运行控制器,也找不到将测试运行状态从 WaitingForController 移动到 Completed 的方法。

还有更多的清理工作要做,但核心是这样工作的:

        this.Run = this.Plan.CreateTestRun(false);
        ConfigureTestRun(build);

        this.Result = CreateRunResults();

        this.Iteration = CreateSingleIteration(suiteRun.Description);

// custom processing omitted for brevity

        this.Result.Iterations.Add(this.Iteration);
        // Attach the run log to the results
        ITestAttachment item = this.Iteration.CreateAttachment(ConfigurationManager.AppSettings["LogFile"], SourceFileAction.None);
        this.Result.State = TestResultState.Completed;
        this.Result.Save();
        this.Run.Attachments.Add(item);
        this.Run.Save();

而试运行配置例程是:

    private void ConfigureTestRun(IBuildDetail build)
    {
        this.Run.DateStarted = DateTime.Now;
        this.Run.DateCompleted = DateTime.Now;
        this.Run.BuildDirectory = build.DropLocation;
        this.Run.BuildFlavor = "debug";
        this.Run.BuildNumber = build.BuildNumber;
        this.Run.BuildPlatform = "test platform";
        this.Run.BuildUri = build.Uri;
        this.Run.Controller = build.BuildController.Name;


        // find the points that correspond to test cases in the run suite
        foreach (ITestPoint point in this.Points)
        {
            if (point.TestCaseExists && point.Plan.Id == this.Plan.Id && point.ConfigurationId == this.Config.Id)
            {
                this.Run.AddTestPoint(point, this.CurrentUser);
            }
        }

        this.Run.Save();
    }

【讨论】:

    猜你喜欢
    • 2016-10-16
    • 2018-12-30
    • 2023-03-18
    • 2014-12-08
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    相关资源
    最近更新 更多