How to use regular expressions with TestNG?

We use regular expressions in TestNG to work with a group of test methods that are named with a certain pattern.

Example

Testng xml file.




   
      
         
         
            
         
      
   

All the test methods with starting name Payment will be excluded from the regression suite.

Example

@Test
public void PaymentHistory(){
   System.out.println("Payment history validation is successful”);
}
@Test
public void Login(){
   System.out.println("Login is successful”);
}
@Test
public void PaymentDefault(){
   System.out.println("Payment default verification is successful”);
}

Login() will be executed, but all the methods starting with name Payment will be excluded from execution. This is achieved using regular expression(Payment.*).

Updated on: 2020-06-11T12:45:23+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements