![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
<?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "Tutorialspoint Test "> <test name = "Test Cycle"> <classes> <class name = "TestRegularExpression" /> <methods> <exclude name= “Payment.*”/> </methods> </classes> </test> </suite>
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.*).
Advertisements