How to Include and Exclude Test Methods in TestNG – XML & Regex (Complete Guide)
By Bhau Automation • Master Include/Exclude Test Cases in TestNG
🎯 What You Will Learn in This Video
- How to include test methods in testng.xml
- How to exclude test methods in testng.xml
- How to exclude a method in TestNG XML
- Using regular expressions (regex) for include & exclude
- Real-time Selenium + TestNG examples
- Interview questions on include & exclude in TestNG
💡 Pro Tip: Include & Exclude feature helps you run selective test cases like Smoke, Sanity, Regression without changing code.
📌 What is Include & Exclude in TestNG?
Include and Exclude in TestNG allows you to control which test methods should be executed and which should be skipped using testng.xml. This is extremely useful in real-time projects when you want to run only specific test cases.
⚙ How to Include Test Methods in testng.xml
❌ How to Exclude Test Methods in testng.xml
🔍 Include & Exclude Using Regular Expressions (Regex)
📚 Prerequisites (Recommended)
- TestNG Framework & Annotations – Part 1
- TestNG Annotations Execution Flow – Part 2
- TestNG Parameterization – Part 3
❓ Common Interview Questions
Q: How do you exclude a method in TestNG?
A: By using
Q: Can we include and exclude methods using regex?
A: Yes, TestNG supports regular expressions to include or exclude multiple methods dynamically.
🎥 Watch the Complete Video Tutorial
👉 Watch on YouTube: Include & Exclude Test Methods in TestNG
🎓 Key Takeaways
- Include/Exclude helps control test execution without code changes
- Useful for Smoke, Sanity & Regression suites
- Regex gives dynamic control over test selection
- Must-know topic for TestNG interview questions
🚀 Created with ❤️ by Bhau Automation