Sunday, July 7, 2024

Re-Run Failed test cases :

Re-Run Failed test cases :

            test1()

            test2()

            test3()

            test4()

 

2 test methods may fail --  re-run only failed Test methods

100 tc  -   80  will passs

                20  will fail

 run only failed Tests --  what ?    we will comment 80 classes in testng.xml file

if we run failed test cases i.e 20 --   it may pass  all test cases 20 .

Running Failed Tests in "TestNg-Failed.xml" file :

By default Testng creates one more 'testng-failed.xml' file in 'test-output' folder for failed test Methods

C:\brahma\Practise\SelniumPractiseNew\Aug2022BatchWorkSpace\SeleniumMorningBatch\test-output

testng-failed.xml  -- run this xml  file:


package TestNGBasics3;

import org.testng.Assert;

import org.testng.annotations.Test;

public class A {

            @Test

            public void testA()

            {

                        System.out.println("stmt-1 from test A");

            }

           

            @Test

            public void testB()

            {

                        System.out.println("stmt-1 from test B");

                        // Failing purposefully

                        Assert.assertEquals("ram", "sita");// Fail --Fail method testB

                       

            }

}

 

package TestNGBasics3;

import org.testng.Assert;

import org.testng.annotations.Test;

public class B {

           

            @Test

            public void testC()

            {

                        System.out.println("stmt-1 from test C");

            }

            @Test

            public void testD()

            {

                        System.out.println("stmt-1 from test D");

                        // Failing purposefully

                                                Assert.assertEquals("ram", "sita");// Fail --Fail method testD

                       

            }

}

------------

<?xml version="1.0" encoding="UTF-8"?>

<suite name ="My suite">

           

  

            <test name="My test">

                        <classes>

                                    <class name="TestNGBasics2.A">  </class>

                                    <class name="TestNGBasics2.B">  </class>              

                        </classes>      

            </test>

</suite>

Run As testng :

it fails 2 test methods from class A, Class - B

                i.e testB() and testD()

 

By default Testng creates one more 'testng-failed.xml' file in 'test-output' folder for failed test Methods

C:\brahma\Practise\SelniumPractiseNew\Aug2022BatchWorkSpace\SeleniumMorningBatch\test-output

testng-failed.xml  -- run this xml  file:

it contains only Failed test methods, what ever  it is failed

 

testng-failed.xml:

-------------------

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="Failed suite [My suite]">

  <test thread-count="5" name="My test(failed)">

  

    <classes>

      <class name="TestNGBasics2.A">

        <methods>

          <include name="testB"/>

        </methods>

      </class> <!-- TestNGBasics2.A -->

     

      <class name="TestNGBasics2.B">

        <methods>

          <include name="testD"/>

        </methods>

      </class> <!-- TestNGBasics2.B -->

      

    </classes>

  </test> <!-- My test(failed) -->

</suite> <!-- Failed suite [My suite] -->

 

FAQ ** How do you rerun Failed test cases ?

---------------------------------------

1.  we will comment  passed classes - in testng.xml file  and we will keep only failed classes, run from testng.xml file

2.  by default testNG creates one more xml file with anme "tesng-failed.xml"  in "test-output" fodler.

which contains only failed test methods only.

We will  run tesng-failed.xml, so it will run failed test methods only .

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...