All subjects

Web Automation · Interview subject

TestNG Interview Questions

Annotations, listeners, retry analyzer, data providers and parallel suites.

53 questions

Quick interview answer

Run testng-failed.xml from target/surefire-reports, or attach an IRetryAnalyzer with a bounded retry count.

Detailed explanation

TestNG generates testng-failed.xml after a run; executing it reruns only failures with their dependencies. For infra flakiness, IRetryAnalyzer retries at runtime — but cap it at 1-2 and always report the retry so genuine bugs are not hidden.

java
1public class RetryAnalyzer implements IRetryAnalyzer {
2 private int count = 0;
3 private static final int MAX = 2;
4
5 @Override public boolean retry(ITestResult result) {
6 if (count < MAX) { count++; return true; }
7 return false;
8 }
9}

Real-world example

Nightly Jenkins job runs the suite, then a second stage runs testng-failed.xml before declaring the build red.

Interview tip

Add: 'I tag retried tests in the report so flakiness stays visible.'

Next subjectMaven