← Back to libraryQuestion 284 of 468
🔬TestNG & JUnitIntermediate

Reporting and Maven Surefire Integration

📌 Definition:

Both frameworks integrate with Maven Surefire (for unit tests) / Failsafe (for integration tests) to run in the build and produce reports. TestNG emits its own HTML/XML reports; results also feed CI and richer reporters (Allure, ExtentReports).

📖 Detailed Explanation:

Surefire runs tests during mvn test and generates XML/txt reports under target/surefire-reports (consumed by CI dashboards); Failsafe runs integration tests during the verify phase. TestNG additionally produces its own emailable HTML report and testng-results.xml, and you can point Surefire at a specific suiteXmlFile. For richer, shareable reports, teams add Allure or ExtentReports (via listeners/extensions) with screenshots and trends. Configuring Surefire (which tests, which groups/tags, which testng.xml, parallelism, fork counts) is central to CI; misconfigured includes/patterns causing 'no tests run' is a frequent issue.

🔑 Key Points:
  • Surefire (unit)/Failsafe (integration) run tests in the Maven build
  • Reports in target/surefire-reports (XML/txt) → CI dashboards
  • TestNG adds its own HTML + testng-results.xml; point Surefire at suiteXmlFile
  • Add Allure/ExtentReports for rich, screenshot-rich dashboards
🌍 Real-World Example:

CI runs mvn verify; Failsafe executes the REST Assured integration tests, Surefire the unit tests, and an Allure plugin turns the results into a dashboard with pass/fail trends and failure screenshots.

🎯 Scenario-Based Interview Question:

mvn test reports 'No tests were executed' even though tests exist. What Surefire configuration issues typically cause this?