← Back to libraryQuestion 270 of 468
🔬TestNG & JUnitIntermediate

testng.xml — Suite Configuration

📌 Definition:

testng.xml is TestNG's XML file that defines a test suite: which classes/packages/methods to run, groups to include/exclude, parameters, listeners, and parallel settings — all WITHOUT changing test code.

📖 Detailed Explanation:

A suite (<suite>) contains one or more <test> blocks, each listing <classes>, <packages>, or <methods>, and can <include>/<exclude> groups. You pass <parameter> values into tests (@Parameters), register <listeners>, and enable parallelism (parallel='methods' thread-count='4'). This externalized configuration is a TestNG differentiator: CI can run different suites (smoke.xml, regression.xml) by pointing Surefire at a different XML, and testers control scope, order, and threads declaratively. Maintaining suite XMLs per environment/stage is a common framework practice; a wrong class path or group name in the XML is a frequent 'no tests run' cause.

🔑 Key Points:
  • XML defines suite: classes/packages/methods, groups, params, parallel
  • include/exclude groups; pass @Parameters; register listeners
  • Different XMLs (smoke.xml/regression.xml) per CI stage — no code change
  • Configure parallel + thread-count declaratively
🌍 Real-World Example:

A smoke.xml includes only the @smoke group with parallel='methods' thread-count='3', so the PR pipeline runs the fast smoke subset in parallel just by pointing Surefire at that XML.

🎯 Scenario-Based Interview Question:

How do you run only smoke tests in parallel on 4 threads for PRs and the full suite serially nightly, without editing test code?