TestNG Reports
Here’s a breakdown of TestNG’s built-in reporting features in Eclipse, plus how to generate/view the standard HTML reports and use the Reporter API to add your own entries.
1. TestNG Dashboard & “Report” View in Eclipse
When you install the TestNG Eclipse plugin, you get a TestNG Results perspective/view. After you run a suite or class:
1. Console Output
- You’ll see TestNG’s execution summary: total methods run, passed, failed, skipped, and total time.
- Example footer:
===============================================
Default Suite
Total tests run: 5, Failures: 1, Skips: 0
===============================================
2. TestNG Results View
- Open via Window → Show View → Other… → TestNG → TestNG Results
- Shows a tree of <suite> → <test> → <class> → <method>, color-coded (green/red/grey).
- Clicking a method shows its stack trace (on failure) or log output.
3. “Report” Section
- In the same view you’ll find a Report tab, which renders a quick HTML snapshot of your results (pie chart of pass/fail, method list).
- It’s purely in-Eclipse; you don’t need to open an external browser.
2. The Console Report
Every TestNG run emits a plain-text report to the Eclipse console by default:
- Start banner: suite and test names, thread info
- Per-test logging: whatever your @Before…/@Test methods System.out.println or Reporter.log(…, true)
- End summary:
===============================================
SuiteName
Total tests run: 10, Pass: 9, Failures: 1, Skips: 0
===============================================
You can adjust verbosity with <suite parallel=”…” verbose=”2″> in your testng.xml (higher verbose gives more detail).
3. Emailable Report
TestNG automatically creates an emailable report (HTML) in your project’s test-output folder:
- Path: project-root/test-output/emailable-report.html
- Content: a simple table of all test methods (status, start/end times, exception stack traces).
- How to view:
Run your tests.
In Eclipse’s Package Explorer, expand the project → test-output → double-click emailable-report.html.
It opens in Eclipse’s HTML editor or external browser.
4. Index Report
In the same test-output directory you’ll also find:
- index.html – a dashboard-style entry point.
- It links to:
emailable-report.html
index-results.html (detailed per-suite report)
individual method/class logs
- Open index.html the same way—this gives you a richer navigation tree and embedded charts.
5. Custom Logging with Reporter
If you want to inject your own messages into these HTML reports (and the console), use TestNG’s Reporter API:
import org.testng.Reporter;
import org.testng.annotations.Test;
public class ReporterExample {
@Test
public void exampleTest() {
Reporter.log("→ Starting exampleTest()", true);
// … test steps …
boolean passed = /* your validation */;
Reporter.log("→ Validation result: " + (passed ? "PASS" : "FAIL"), true);
assert passed : "Check failed!";
}
}
- Reporter.log(String msg, boolean toConsole)
When toConsole=true, it also prints to the Eclipse console.
Regardless, it’s captured in emailable-report.html under the “Reporter output” column.
6. Advanced: Custom Reporters & Listeners
If you need more than the built-ins, TestNG lets you hook in:
- IReporter to generate completely custom HTML/PDF.
- IInvokedMethodListener or ITestListener to capture screenshots or write to Log4J.
You register these either via @Listeners on your classes or in testng.xml:
<suite name="MySuite">
<listeners>
<listener class-name="com.example.MyCustomReporter"/>
</listeners>
…
</suite>
Quick Recap
- Eclipse Dashboard: TestNG Results view + console summary.
- Emailable Report: test-output/emailable-report.html – email-friendly table.
- Index Report: test-output/index.html – interactive dashboard with links and charts.
- Reporter API: Reporter.log(…) to add custom messages to both console and HTML.
With these you can both view and enhance TestNG’s built-in reporting right inside Eclipse (or any CI/CD pipeline).