ITestCaseResult.Iterations.Count returns 0 for a test with iterations

白昼怎懂夜的黑 提交于 2019-12-11 05:52:53

问题


I have a couple of simple web tests that use data sources. Each web test contains only one request.

After they run it's pretty hard to detect why they failed, given that they are quite a few (80) and each has a number of rows that varies between 1 and 150.

Therefore, I used the TFS SDK to access the results programmatically, after publishing the test results to a build in TFS.

Here is the relevant part of the code:

foreach (var testRun in testRuns)
{
    Console.WriteLine(string.Format("{0}", testRun.Title));
    ITestCaseResultCollection testCases = testRun.QueryResults();
    foreach (ITestCaseResult testcase in testCases)
    {
        Console.WriteLine(string.Format("{0}: {1}", testcase.TestCaseTitle, testcase.Outcome));
        if (TestOutcome.Passed != testcase.Outcome)
        {
            Console.WriteLine(string.Format("\tNumber of iterations: {0}", testcase.Iterations.Count));
            foreach (ITestIterationResult iteration in testcase.Iterations)
            {
                Console.WriteLine(string.Format("\t{0}: {1}", iteration.IterationId, iteration.Outcome));
            }
        }
    }
}

The problem is that testcase.Iterations.Count is always 0. Everything else is displayed correctly. If I open the test results from Visual Studio, I can see the iterations and the details for each.

What am I missing?

Thanks.


回答1:


After investigating a bit more I realized I was looking in the wrong place.

What I'm interested in is to get the details for all the rows that a databound test is running against, while ITestCaseResult.Iterations points to the iterations defined for a certain test case.

The information I'm interested in is retrieved by accessing the attachments of a test case result:

foreach (ITestAttachment att in testCaseResult.Attachments)
{
    Console.WriteLine(string.Format("{0}\t{1}", att.Name, att.AttachmentType));
}

especially the ones with these types: TmiTestResultDetail TmiTestRunReverseDeploymentFiles

How to extract the information in these attachments constitutes a different question. :)



来源:https://stackoverflow.com/questions/11436780/itestcaseresult-iterations-count-returns-0-for-a-test-with-iterations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!