我正在尝试创建一个包含在测试用例中执行的每个步骤的结果的报告,并且我能够检索测试步骤、预期结果、步骤结果、错误消息、附件。
测试步骤和预期结果按 MTM 上看到的正确顺序列出,但似乎为我检索的所有测试用例重新安排了步骤结果和错误消息。这是我的代码,请帮忙。
foreach (ITestSuiteEntry testcase in ts.TestCases)
{
var testResults = testProject.TestResults.ByTestId(testcase.TestCase.Id);
foreach (ITestCaseResult result in testResults)
{
for (int actionIndex = 0; actionIndex < testcase.TestCase.Actions.Count; actionIndex++)
{
resultData = new TestResultData();
var actionStep = testcase.TestCase.Actions[actionIndex] as ITestStep;
if (actionStep != null)
{
resultData.TestCaseName = result.TestCaseTitle;
resultData.Step = Regex.Replace(actionStep.Title, @"<[^>]+>| ", "").Trim();
resultData.ExpectedResult = Regex.Replace(actionStep.ExpectedResult, @"<[^>]+>| ", "").Trim();
}
var topIteration = result.Iterations.FirstOrDefault();
if (topIteration != null && actionIndex < topIteration.Actions.Count)
{
var actionResult = topIteration.Actions[actionIndex];
resultData.StepOutcome = actionResult.Outcome.ToString();
resultData.Comment = actionResult.ErrorMessage;
foreach (var attachment in actionResult.Attachments)
{
resultData.AttachmentName = attachment.Name;
resultData.AttachmentUri = attachment.Uri.ToString();
}
}
resultDataList.Add(resultData);
}
}
}