How To Ignore TestNG Test | TestNG Tutorial
At times we may face some situations where our code is not ready and the test cases written to test a particular method may fail. In such cases, we could use TestNG annotation @Test(enabled = false). This TestNG annotation allows us to ignore testng test.
If a test method is annotated with @Test(enabled = false), then the test case that is not ready to test is ignored.
Now, let’s see how to ignore TestNG test using a script.
Script – Test Case 1:
package softwareTestingMaterial; import org.testng.annotations.Test; public class TestCase1 { @Test public void printClass(){ System.out.println("This is Test Case 1"); } }
Script – Test Case 2: I would like to ignore this test from the test execution
package softwareTestingMaterial; import org.testng.annotations.Test; public class TestCase2 { @Test (enabled=false) public void printClass2(){ System.out.println("This is Test Case 2"); } }
testNg.xml file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="softwaretestingmaterial"> <test name="testngTest"> <classes> <class name="softwareTestingMaterial.TestCase1" /> <class name="softwareTestingMaterial.TestCase2" /> </classes> </test> </suite>
Check below video to see how to create and run testng.xml
Please be patient. The video will load in some time.
If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.
Console Output:
[TestNG] Running: This is Test Case 1 =============================================== softwaretestingmaterial Total tests run: 1, Failures: 0, Skips: 0 ===============================================
Â
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.
Hi Raj,
what is difference between ignoring(enable=false) the TC and skipping(throw new Skipexeption TC? Both serve same purpose rt to not to execute particular TC. In the interview if they How to skip the TC then do we need to tell both the options?
Thank you
Hi Deepa,
‘@Test(enabled = false)’ is used to bypass the test which is not ready to test.
‘throw new SkipException’ is used to throw an exception to skip some condition.