C# 使用tfs api在tfs中通过测试用例
我有以下代码来通过TFS/MTM中的测试用例。我已经实现了从外部通过测试用例,但是当我检查测试用例的内部步骤时,它们没有通过。我希望通过测试用例的每个操作来通过测试用例。 谢谢你的帮助C# 使用tfs api在tfs中通过测试用例,c#,tfs,C#,Tfs,我有以下代码来通过TFS/MTM中的测试用例。我已经实现了从外部通过测试用例,但是当我检查测试用例的内部步骤时,它们没有通过。我希望通过测试用例的每个操作来通过测试用例。 谢谢你的帮助 ITestPlan tp = testinsuitesd.Plan; // foreach (ITestCase testcase in allTestCases) //{ ITestRun testRun = testinsuitesd.Plan.CreateTestRun(false); ITestPoin
ITestPlan tp = testinsuitesd.Plan;
// foreach (ITestCase testcase in allTestCases)
//{
ITestRun testRun = testinsuitesd.Plan.CreateTestRun(false);
ITestPointCollection testPoints = tp.QueryTestPoints("select * from TestPoint where suiteId= "+ testinsuitesd.Id);
foreach(ITestPoint testRuns in testPoints)
{
testRun.AddTestPoint(testRuns, null);
}
testRun.Save();
ITestCaseResultCollection testCaseResult = testRun.QueryResults(); //code to Pass the test Case
foreach (ITestCaseResult testResult in testCaseResult)
{
ITestIterationResult iterationResult;
ITestActionResult actionResults;
iterationResult = testResult.CreateIteration(1);
//actionResults = testResult.CreateIteration(1);
foreach (ITestAction testStep in testResult.GetTestCase().Actions)
{
ITestActionResult stepResult = iterationResult.CreateStepResult(testStep.Id);
//stepResult.ErrorMessage = String.Empty;
stepResult.Outcome = TestOutcome.Passed; //you can assign different states here
iterationResult.Actions.Add(stepResult);
//actionResults.Add(stepResult);
// iterationResult.Actions.Add(stepResult);
// actionResults. Add(stepResult);
}
iterationResult.Outcome = TestOutcome.Passed;
testResult.Iterations.Add(iterationResult);
testResult.Outcome = TestOutcome.Passed;
testResult.State = TestResultState.Completed;
testResult.Save();
}
testCaseResult.Save(false);
// testCaseResult.
testRun.Save();
testRun.Refresh();
tp.Save();
请尝试以下代码:
var tfsRun = _testPoint.Plan.CreateTestRun(false);
tfsRun.DateStarted = DateTime.Now;
tfsRun.AddTestPoint(_testPoint, _currentIdentity);
tfsRun.DateCompleted = DateTime.Now;
tfsRun.Save(); // so results object is created
var result = tfsRun.QueryResults()[0];
result.Owner = _currentIdentity;
result.RunBy = _currentIdentity;
result.State = TestResultState.Completed;
result.DateStarted = DateTime.Now;
result.Duration = new TimeSpan(0L);
result.DateCompleted = DateTime.Now.AddMinutes(0.0);
var iteration = result.CreateIteration(1);
iteration.DateStarted = DateTime.Now;
iteration.DateCompleted = DateTime.Now;
iteration.Duration = new TimeSpan(0L);
iteration.Comment = "Run from TFS Test Steps Editor by " + _currentIdentity.DisplayName;
for (int actionIndex = 0; actionIndex < _testEditInfo.TestCase.Actions.Count; actionIndex++)
{
var testAction = _testEditInfo.TestCase.Actions[actionIndex];
if (testAction is ISharedStepReference)
continue;
var userStep = _testEditInfo.SimpleSteps[actionIndex];
var stepResult = iteration.CreateStepResult(testAction.Id);
stepResult.ErrorMessage = String.Empty;
stepResult.Outcome = userStep.Outcome;
foreach (var attachmentPath in userStep.AttachmentPaths)
{
var attachment = stepResult.CreateAttachment(attachmentPath);
stepResult.Attachments.Add(attachment);
}
iteration.Actions.Add(stepResult);
}
var overallOutcome = _testEditInfo.SimpleSteps.Any(s => s.Outcome != TestOutcome.Passed)
? TestOutcome.Failed
: TestOutcome.Passed;
iteration.Outcome = overallOutcome;
result.Iterations.Add(iteration);
result.Outcome = overallOutcome;
result.Save(false);
var tfsRun=\u testPoint.Plan.CreateTestRun(false);
tfsRun.DateStarted=DateTime.Now;
AddTestPoint(_testPoint,_currentIdentity);
tfsRun.DateCompleted=DateTime.Now;
tfsRun.Save();//所以结果对象被创建
var result=tfsRun.QueryResults()[0];
result.Owner=\u currentIdentity;
result.RunBy=\u currentIdentity;
result.State=TestResultState.Completed;
result.datestart=DateTime.Now;
结果.持续时间=新的时间跨度(0L);
result.DateCompleted=DateTime.Now.AddMinutes(0.0);
var iteration=result.CreateIteration(1);
iteration.datestart=DateTime.Now;
iteration.DateCompleted=DateTime.Now;
迭代持续时间=新的时间跨度(0L);
iteration.Comment=“通过”+\u currentIdentity.DisplayName从TFS测试步骤编辑器运行;
对于(int actionIndex=0;actionIndex<\u testEditInfo.TestCase.Actions.Count;actionIndex++)
{
var testAction=_testEditInfo.TestCase.Actions[actionIndex];
如果(测试是ISharedStepReference)
继续;
var userStep=_testEditInfo.SimpleSteps[actionIndex];
var stepResult=iteration.CreateStepResult(testAction.Id);
stepResult.ErrorMessage=String.Empty;
stepResult.output=userStep.output;
foreach(userStep.AttachmentPaths中的var attachmentPath)
{
var attachment=stepResult.CreateAttachment(attachmentPath);
stepResult.Attachments.Add(附件);
}
迭代.Actions.Add(步骤结果);
}
var overallOutcome=\u testEditInfo.SimpleSteps.Any(s=>s.Outcome!=TestOutcome.Passed)
? 测试结果。失败
:testoutput.Passed;
迭代结果=超额收益;
result.Iterations.Add(迭代);
结果:结果=超额收益;
结果:保存(假);
此外,还有一些关于TFS API的链接可以帮助您: