At times we have a scenario, for certain methods our code is not yet complete and those test methods will be marked as fail during the execution, if we execute it with other methods.
Problem Statement :
Suppose there are 100 test methods to be executed out of which 20 test methods failed and we are not sure the failures are due to incomplete code or real defects from the AUT(Application under Test)
Solution : TestNG has provided an option to skip or bypass the incomplete test methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import org.testng.annotations.Test; public class withoutTestNGIgnore { @Test public void testMethod1() { System.out.println("testMethod1 is complete"); } @Test public void testMethod2() { System.out.println("testMethod2 is incomplete…. "); } @Test public void testMethod3() { System.out.println("testMethod3 is complete "); } @Test public void testMethod4() { System.out.println("testMethod4 is incomplete… "); } } |
OUTPUT :
TestNG-Without-Ignore-Method
In the above example testMethod2,testMethod4 are not completed yet. Hence if we execute with these two methods, it will be marked as failed. TestNG has provided an option to choose which methods to execute by giving @Test(enabled=true) and to skip the methods we can give @Test(enabled=false) method.
Example 2 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import org.testng.annotations.Test; public class Enable { @Test(enabled=true) public void testMethod1() { System.out.println("testMethod1 is complete"); } @Test(enabled=false) public void testMethod2() { System.out.println("testMethod2 is incomplete…. "); } @Test(enabled=true) public void testMethod3() { System.out.println("testMethod3 is complete "); } @Test(enabled=false) public void testMethod4() { System.out.println("testMethod4 is incomplete… "); } } |