locked
Test Result outcome is not reflecting on Test Case RRS feed

  • Question

  • Hi,

    I am working on a task, update Test Case result and status using Microsoft.TeamFoundation.TestManagement.Client in VSTS based on information from other third party testing tool.  Following are the steps what I am doing to update test case details in VSTS.  

    1) Get Test Case based on Name given in Third Party Tool
    2) Create a Test Run
        2.1) Assign Name with Test_Case_Name from Third Party Tool
        2.2) Assign Completed with Modified Date from Third Party Tool
        2.3) Add Third Party Tool Description as Comment
        2.4) Assign Test Run with found Test Case
    3) Query Test Results for Test Case which created above
        3.1) Assign Outcome with Status from Third Party Tool
        3.2) Change Status as "Completed".
        3.3) Add Third Party Tool Description as Comment

    I am able to create test run and attach test case to it.  And update test result details.  But this test result out come is not reflecting in test case in test case list under test plan menu.  Here I am including the code, Please review and let me know how to fix it.

    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.TestManagement.Client;
    using Microsoft.TeamFoundation.Framework.Client;

            public bool UpdateTestCases(string projectName, List<VSTS.TestCase> VSTSTestCases)
            {
                try
                {
                    TeamFoundationServer server = new TeamFoundationServer(_TFSServer);
                    server.Authenticate();
                    ITestManagementService tms = server.GetService<ITestManagementService>();
                    ITestManagementTeamProject project = tms.GetTeamProject(projectName);

                    ITestCaseResultHelper results = project.TestResults;

                    ITestRunHelper runs = project.TestRuns;

                    ITestConfigurationHelper configs = project.TestConfigurations;
                    ITestConfiguration config = null;
                    for (int i = 0; i < 10; i++)
                    {
                        config = configs.Find(i);
                        if (config != null)
                            break;
                    }

                    Guid TeamFoundationId = project.TfsIdentityStore.RecentUserNames[0].TeamFoundationId;
                    TeamFoundationIdentity identitystore = project.TfsIdentityStore.FindByTeamFoundationId(TeamFoundationId);

                    //string wiql = "select * from TestRun"; //where TestRun.Title = '{0}'
                    //IEnumerable<ITestRun> TestRuns = runs.Query(wiql);

                    ITestCaseHelper cases = project.TestCases;
                    string wiqlTestCases = string.Format("SELECT * FROM WorkItems WHERE [System.TeamProject] = '{0}'  AND  [System.WorkItemType] = 'Test Case'", projectName);
                    IEnumerable<ITestCase> TestCases = cases.Query(wiqlTestCases);

                    foreach (VSTS.TestCase VSTSTestCase in VSTSTestCases)
                    {
                        try
                        {
                            //udpate test case
                            ITestCase TestCase = (from tc in TestCases where tc.Title == VSTSTestCase.name select tc).FirstOrDefault();
                            if (TestCase != null)
                            {
                                ITestCase objTestCase = cases.Find(TestCase.Id);

                                ITestRun objTestRun = runs.Create();
                                objTestRun.Title = VSTSTestCase.name;
                                objTestRun.DateCompleted = objTestCase.DateModified;
                                objTestRun.AddTest(objTestCase.Id, config.Id, identitystore);
                                objTestRun.Save();
                                objTestRun.Comment = VSTSTestCase.description;
                                objTestRun.Save();

                                ITestCaseResultCollection resultcoll = objTestRun.QueryResults();
                                foreach (ITestCaseResult result in resultcoll)
                                {
                                    TestOutcome objTestOutcome;
                                    if (Enum.TryParse(VSTSTestCase.state, out objTestOutcome))
                                        result.Outcome = objTestOutcome;
                                    result.State = TestResultState.Completed;
                                    result.Comment = VSTSTestCase.description;
                                    result.Save();

                                }
                                objTestRun.Save();

                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(string.Format("{0} - {1}", VSTSTestCase.name, ex.Message));
                        }
                    }
                    return true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return false;
                }
            }

    Advance Thanks for your help.


    • Edited by NTon Thursday, January 12, 2017 11:05 AM
    • Moved by Limitxiao Gao Friday, January 13, 2017 1:51 AM Related to VSTS
    Thursday, January 12, 2017 11:05 AM

All replies

  • Hi NTon,

    Thank you for posting here.

    This forum is discussing Team Foundation Server. Your issue is related to Visual Studio Team Service. I will move this thread to corresponding forum.

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 13, 2017 1:49 AM
  • Hi

    You cannot mark outcome for test cases. You need to mark outcome for test points. See this blog for API usage snippets: https://blogs.msdn.microsoft.com/aseemb/2012/08/06/code-snippets-on-test-management-apis/. Specifically, "Snippet #8 Create a test run, Mark steps passed/failed, associate attachments with it" will be helpful.

    Thanks,
    Manoj

    Monday, January 16, 2017 6:24 AM