Skip TestNG Test | TestNG Tutorial
How To Skip TestNG Test:
package softwareTestingMaterial; import org.testng.annotations.Test; import org.testng.SkipException; public class SkipTestCase { @Test public void aSkipTest(){ String condition ="Skip Test"; if(condition.equals("Skip Test")){ // throw new SkipException("Skipping - This is not ready for testing "); }else{ System.out.println("I am in else condition"); } System.out.println("I am out of the if else condition"); } @Test public void nonSkipTest(){ System.out.println("No need to skip this test"); } }
In the output console, we could see “out of loop” from first test method “aSkipTest” and No need to skip this test from second test method “nonSkipTest”
Output Console:
[TestNG] Running: I am out of the if else condition No need to skip this test =============================================== Default suite Total tests run: 2, Failures: 0, Skips: 0 ===============================================
package softwareTestingMaterial; import org.testng.annotations.Test; import org.testng.SkipException; public class SkipTestCase { @Test public void aSkipTest(){ String a ="Skip Test"; if(a.equals("Skip Test")){ throw new SkipException("Skipping - This is not ready for testing "); }else{ System.out.println("I am in else condition"); } System.out.println("I am out of the if else condition"); } @Test public void nonSkipTest(){ System.out.println("No need to skip this test"); } }
Output Console:
[TestNG] Running: No need to skip this test PASSED: nonSkipTest SKIPPED: aSkipTest =============================================== Default suite Total tests run: 2, Failures: 0, Skips: 1 ===============================================
Skip exception thrown and the remaining part of the first test method “aSkipTest” not executed and control reached to second test method “nonSkipTest” and printed the value as “No need to skip this test”
You could find the complete TestNG tutorial here.
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.
Hello Raj,
I guess it shows no of Skips for SkipException in Results of running.
Skipped: 1
Hi Deepa, thanks for letting me know. You are correct. I have updated that. If you are interested to write on our blog, just follow our guest post link. Thanks.
Thanks Raj.