我正在尝试使用TFS API单独更新自动化运行的测试结果。 我在这里尝试过其他问题的建议(特别是如何使用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并检索我需要的所有数据,但是为新的测试运行添加测试点让我发疯。
我做错了什么?
I'm trying to use the TFS API to update test results from automation run separately. I've tried the suggestions from other questions here (particularly How to create a test run and result using the Team Foundation Server API?) as well as from searches elsewhere. No matter what I try I have the same problem: every time I try to add a test point to a test run, I receive the error -
Microsoft.TeamFoundation.TestManagement.Client.TestManagementInvalidOperationException: This test run cannot be created with the test points.The test points are retrieved from TFS using WIQL, and I check each test point to ensure that it is correct for the test plan, test suite, and test configuration before I attempt to add it.
I can't save the test run without test points.
Sample code (I've gone through so many attempts that my code is now beyond messy)
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); } }And the method to configure the test run:
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(); }I'm able to connect to TFS and retrieve all the data I need but adding test points to a new test run is driving me crazy.
What have I done wrong?
最满意答案
经过疯狂的试验和我的头撞墙后,我找到了答案。
对于那些好奇的人,以下是它的工作原理:
如果我使用ITestManagementService.TestRuns.Create();创建测试运行ITestManagementService.TestRuns.Create(); 我可以添加测试用例但不能添加测试点。
如果我使用ITestPlan.CreateTestRun(isAutomated);创建测试运行ITestPlan.CreateTestRun(isAutomated); 我可以添加测试点而不是测试用例。
我过度复杂的事情试图让这个工作 - 我现在已经清理了很多混乱,让我的应用程序正确地将测试结果报告给TFS。
正如Jason Prickett博客所描述的那样,我或多或少地使用了假装。
我发现的一件事是我无法将运行定义为自动运行,因为我的环境中没有测试运行控制器,并且无法找到将测试运行状态从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(); }After an insane amount of experimenting and beating my head against the wall, I've found the answer.
For those who are curious, here's how it works:
If I create the test run using ITestManagementService.TestRuns.Create(); I can add Test Cases but not Test Points.
If I create the test run using ITestPlan.CreateTestRun(isAutomated); I can add Test Points but not Test Cases.
I overcomplicated things a lot trying to get this working - I've now cleaned up a lot of the mess and have my application correctly reporting test results to TFS.
I'm using a fake build more or less as described by Jason Prickett's blog.
One thing I did find was that I couldn't define the run as an automated run because I have no test run controllers in my environment and couldn't find a way to move the test run state from WaitingForController to Completed.
There's more cleanup to go but the core works this way:
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();And the test run configuration routine is:
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(); }更多推荐
发布评论