locked
Rerun failed tests RRS feed

  • Question

  • Hi,

    To execute automated acceptance tests I use tcm.exe from a PS script. Test run is addded by tcm.exe and PS script waits until the test execution on agents is completed.

    I've found how can I get the list of the failed test cases in a test run. I guess that same approach can be implemented using Powershell as well.

    How could I rerun the failed test cases in the original test run using a Powershell script?

    As I can rerun them from the MTM UI manually.

    Thanks

    Peter



    • Edited by Peter Dobos Wednesday, January 27, 2016 9:29 AM
    Wednesday, January 27, 2016 8:58 AM

Answers

  • Hi Starain,

    To rerun a failed automated test you can use the MTM UI

    1. Open the test run which contains the failed tests
    2. Select the tests you wanted to rerun
    3. At the top of the test case grid there is toolbar with a Re-run test button

    Using the TFS API:

            /// <summary>
            /// Reruns failed test cases
            /// </summary>
            /// <param name="run">Test run to process</param>
            /// <returns>Iterable list of test results which were reset</returns>
            public IEnumerable<ITestCaseResult> ReRunFailed(ITestRun run)
            {
                run.Refresh();
                var list = new List<ITestCaseResult>();
                foreach (var result in run.QueryResults().Where(result => result.Outcome == TestOutcome.Failed))
                {
                    result.Reset();
                    list.Add(result);
                }
                return list;
            }

    This method works. After the Reset the test case is executed again.

    I try to implement this method using PS as well.

    Thanky you for your help I really appreciate it.

    Best regards

    Peter


    • Edited by Peter Dobos Friday, January 29, 2016 5:15 PM
    • Marked as answer by Peter Dobos Friday, January 29, 2016 5:20 PM
    Friday, January 29, 2016 5:15 PM

All replies

  • Hi Peter,

    For this scenario, you could refer to these steps below:

    1. Get test results of the test run. (ITestRun run=project.TestRuns.Find(XXX); ITestCaseResults=run.QueryResults(true))
    2. Iterate these test results to get failed tests and TestPointIDs
    3. Get the TestPoint object according to the TestPointId. (ITestPoint point=plan.FindTestPoint(XXX))
    4. Create the test run to run test. (ITestRun run=plan.CreateTestRun(true); run.AddTestPoint(point,null); run.Save();

    Some Code snippets of C#:

    http://blogs.msdn.com/b/aseemb/archive/2012/08/07/code-snippets-on-test-management-apis.aspx

    This is the code of C#, but we could base on it to achieve that through PowerShell.

    There are some articles about TFS API for PowerShell that can help you:

    # PowerShell TFS 2013 API #1 – Get TfsCollection and TFS Services

    http://nkdagility.com/powershell-tfs-2013-api-1-get-tfscollection-and-tfs-services/

    # PowerShell and Team Foundation Server 2013 – Using the TFS API

    http://www.systemcentercentral.com/day-13-powershell-team-foundation-server-2013-using-tfs-api/

    # Using PowerShell and TFS API to list users in TFS 2010

    http://blogs.msdn.com/b/alming/archive/2013/03/07/using-powershell-and-tfs-api-to-list-users-in-tfs-2010.aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 28, 2016 6:20 AM
  • Hi Starain,

    Thank you for your really valuable answer and references. The only question is whether it is possible to add the test points to the ORIGINAL TestRun where tests failed. When I use the MTM UI to rerun the failed tests there is no new TestRun instance added.

    I'm going to try :-) 

    Regards

    Peter

    Thursday, January 28, 2016 3:56 PM
  • Hi Peter,

    First, as far as I know there isn’t way to rerun the failed test with the exist test run, how do you do it.

    Secondly, based on my test with TFS API (add test point to exist test run), it won’t run the test again. So, in my opinion, we can’t rerun the test through MTM.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 29, 2016 6:46 AM
  • Hi Starain,

    To rerun a failed automated test you can use the MTM UI

    1. Open the test run which contains the failed tests
    2. Select the tests you wanted to rerun
    3. At the top of the test case grid there is toolbar with a Re-run test button

    Using the TFS API:

            /// <summary>
            /// Reruns failed test cases
            /// </summary>
            /// <param name="run">Test run to process</param>
            /// <returns>Iterable list of test results which were reset</returns>
            public IEnumerable<ITestCaseResult> ReRunFailed(ITestRun run)
            {
                run.Refresh();
                var list = new List<ITestCaseResult>();
                foreach (var result in run.QueryResults().Where(result => result.Outcome == TestOutcome.Failed))
                {
                    result.Reset();
                    list.Add(result);
                }
                return list;
            }

    This method works. After the Reset the test case is executed again.

    I try to implement this method using PS as well.

    Thanky you for your help I really appreciate it.

    Best regards

    Peter


    • Edited by Peter Dobos Friday, January 29, 2016 5:15 PM
    • Marked as answer by Peter Dobos Friday, January 29, 2016 5:20 PM
    Friday, January 29, 2016 5:15 PM
  • Hi Peter,

    Thanks for sharing the solution.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 1, 2016 3:19 AM