在测试用例执行后,我使用API在tfs中处理了udpdate tescase结果,但它使所有其他测试用例在测试套件中的状态都为进行中。
它会更新测试套件中测试用例的结果,但也会使位于测试套件中的其余测试用例处于进行中状态。
ITestCaseResult result = run.QueryResults().FirstOrDefault(r => r.TestCaseId == testCase.Id);
if (result != null)
{
testRun.Title = testCase.Title;
result.ComputerName = Environment.MachineName;
result.Outcome = TestOutcome.Passed;
result.Comment = comments;
result.RunBy = testRun.Owner;
result.State = TestResultState.Completed;
result.Save();
}
我期望在运行时传递的特定测试用例id上进行结果更新,并且测试套件中的其余测试用例状态不应更改。
发布于 2019-09-30 10:10:24
没有完整的代码,不知道哪部分是根本原因,但可能与if (result != null)
有关,条件语句会影响结果。
请尝试使用以下代码示例来处理此问题。
publicstaticvoidUpdateResult()
{
TfsTeamProjectCollectiontfs = newTfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(server));
ITestManagementServicetms = tfs.GetService<ITestManagementService>();
ITestManagementTeamProjectproj = tms.GetTeamProject(project);
ITestPlanPlan = proj.TestPlans.Find(1);
IStaticTestSuitesuite = Plan.RootSuite.SubSuites.Where(s => s.Id == 1339).First() asIStaticTestSuite;
ITestCasetestcase = null;
testcase = suite.Entries.Where(e => e.Title == "login").First().TestCase;
ITestRuntestRun = project.TestRuns.Create();
testRun = Plan.CreateTestRun(false);
ITestPointCollectionpoints = Plan.QueryTestPoints("SELECT * FROM TestPoint WHERE TestCaseId ="+ testcase.Id);
foreach(ITestPointp inpoints)
{
testRun.AddTestPoint(p, Plan.Owner);// null);
//testRun.AddTestPoint(p, null);
}
testRun.State = TestRunState.Completed;
testRun.Save();
ITestCaseResultCollectionresults = testRun.QueryResults();
ITestIterationResultiterationResult;
foreach(ITestCaseResultresult inresults)
{
iterationResult = result.CreateIteration(1);
foreach(ITestSteptestStep inresult.GetTestCase().Actions)
{
ITestStepResultstepResult = iterationResult.CreateStepResult(testStep.Id);
stepResult.Outcome = TestOutcome.Passed;
iterationResult.Actions.Add(stepResult);
}
iterationResult.Outcome = TestOutcome.Passed;
result.Iterations.Add(iterationResult);
result.Outcome = TestOutcome.Passed;
result.State = TestResultState.Completed;
result.Save(true);
}
testRun.Save();
testRun.Refresh();
}
更多细节请看这里的类似问题:Changing the outcome field of testcases within a test suite in Tfs
https://stackoverflow.com/questions/58143996
复制相似问题