How to skip the test case if you want
The reason for going to TestNG it solves many of the real world problems. Sometimes we may have to skip executions.
For example, let's say we have 10 test cases and I want to execute only 5 and want to skip the rest of the test cases, TestNG comes with ready to use feature.
Let's loo at how to do that in the below code.
package seleniumWithTestNG;
import org.testng.annotations.Test;
public class SkipTest {
@Test (priority=1)
public void wearSeatBelt(){
System.out.println("Put Seat Belt");
}
@Test (priority=3, enabled=false)
public void turnOnMusic(){
System.out.println("Rock Music On");
}
@Test (priority=2)
public void startEngine(){
System.out.println("Engine started");
}
@Test (priority=4)
public void putFirstGear(){
System.out.println("Car is in first Gear");
}
@Test (priority=5)
public void putSecondGear(){
System.out.println("Car is in second Gear");
}
@Test (priority=6)
public void putThirdGear(){
System.out.println("Car is in third Gear");
}
}
Note that, we have used enabled=false , which tells the TestNG to skip the turnOnMusic() method. See the below output.
Put Seat Belt
Engine started
Car is in first Gear
Car is in second Gear
Car is in third Gear
PASSED: wearSeatBelt
PASSED: startEngine
PASSED: putFirstGear
PASSED: putSecondGear
PASSED: putThirdGear