TestNG @Test attributes - enabled property

There are situations where we need to skip one or more @Test method in testNG,
for this TestNG provides enabled property to skip the execution of methods...

enabled = false (skip the method run)
enabled = true (execute method), it's by default set to true,

NOTE: if we do not mention enabled property, it's set to true

Let's see the code implementation


import org.testng.annotations.Test;

public class TestNGAnnEnabled {

 @Test(enabled=true)
 public void test1()
 {
  System.out.println("This is method: test1");
 }
 @Test(enabled=false)
 public void test2()
 {
  System.out.println("This is method: test2");
 }
 @Test(enabled=true)
 public void test3()
 {
  System.out.println("This is method: test3");
 }
 @Test
 public void test4()
 {
  System.out.println("This is method: test4");
 }
}

OutPut:
This is method: test1
This is method: test3
This is method: test4

Even though test4() does not have enabled property, it's default set to true.

skipped test method - test2() ...

No comments:

Post a Comment