首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TFS 2012 API :无法将测试点添加到测试运行

TFS 2012 API :无法将测试点添加到测试运行
EN

Stack Overflow用户
提问于 2013-06-25 04:20:58
回答 1查看 1.7K关注 0票数 4

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

代码语言:javascript
运行
复制
Microsoft.TeamFoundation.TestManagement.Client.TestManagementInvalidOperationException: This test run cannot be created with the test points.

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

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

示例代码(我已经尝试了这么多次,我的代码现在已经不那么凌乱了)

代码语言:javascript
运行
复制
    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);
        }


     }

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

代码语言:javascript
运行
复制
    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并检索所需的所有数据,但是将测试点添加到新的测试运行中会让我抓狂。

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-27 01:26:53

经过疯狂的实验,我的头撞到了墙上,我找到了答案。

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

  • 如果使用ITestManagementService.TestRuns.Create();创建测试运行,则可以添加测试用例,但不能添加测试点。
  • 如果使用ITestPlan.CreateTestRun(isAutomated);创建测试运行,则可以添加测试点,但不能添加测试用例。

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

正如Jason Prickett's blog所描述的那样,我或多或少使用了一个假的构建。

我确实发现了一件事,那就是我不能将运行定义为自动运行,因为我的环境中没有测试运行控制器,并且无法找到将测试运行状态从WaitingForController移动到已完成的方法。

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

代码语言:javascript
运行
复制
        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();

测试运行配置例程为:

代码语言:javascript
运行
复制
    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();
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17284374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档