Interview question bank

TestNG Interview Questions and Answers

53 TestNG interview questions, each with a short answer you can say in the interview, a detailed explanation, a real-world example and an interview tip; 25 of them are marked as frequently asked. Freshers can start with the first section; experienced testers can jump to the harder questions.

TestNG interview questions for freshers

Beginner3 Years Frequently asked

1. DataProvider vs @Parameters — when do you use each?

Answer: @Parameters injects static values from testng.xml (browser, env); @DataProvider supplies dynamic, multi-row test data from code, Excel, JSON or DB.

Detailed explanation, example and interview tip

DataProvider can be parallel (parallel = true) and can receive Method/ITestContext to vary data per test. Parameters are simple config values and cannot express rows of data.

java
1@DataProvider(name = "loginData", parallel = true)
2public Object[][] loginData() {
3 return JsonDataReader.rows("testdata/login.json");
4}
5
6@Test(dataProvider = "loginData")
7public void login(String user, String pass, String expected) { /* ... */ }

Real-world example

150 checkout permutations driven from a single JSON file.

Interview tip

Mention parallel = true on DataProvider — it is a common follow-up.

Beginner3 Years Frequently asked

2. In what order do TestNG annotations execute?

Answer: @BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite, with @BeforeGroups/@AfterGroups around grouped tests.

Detailed explanation, example and interview tip

Suite-level hooks run once per suite and are the place for shared, expensive setup such as reading config or starting a report. @BeforeMethod runs before every @Test method, which is where per-test driver creation belongs so tests stay independent. Ordering between classes is controlled by the XML, not by the annotations, and alwaysRun=true keeps cleanup hooks running even when setup failed. Depending on @Test execution order is a smell — use dependsOnMethods only for genuine prerequisites.

java
1public class LoginTest {
2 @BeforeMethod(alwaysRun = true)
3 public void setUp() { DriverManager.set(DriverFactory.create("chrome")); }
4
5 @Test(groups = "smoke")
6 public void validLogin() { /* ... */ }
7
8 @AfterMethod(alwaysRun = true)
9 public void tearDown(ITestResult result) {
10 if (result.getStatus() == ITestResult.FAILURE) Screenshot.attach(result.getName());
11 DriverManager.unload();
12 }
13}

Real-world example

Moving driver creation from @BeforeClass to @BeforeMethod removed cross-test contamination in a login suite that shared cookies.

Interview tip

Add 'alwaysRun = true on teardown' — teams lose browsers to leaked sessions without it.

Beginner3 Years Frequently asked

3. What is annotation lifecycle, and why does it matter in TestNG?

Answer: annotation lifecycle is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of annotation lifecycle should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used annotation lifecycle to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner5 Years Frequently asked

4. What is priority, and why does it matter in TestNG?

Answer: priority is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of priority should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used priority to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner7 Years Frequently asked

5. What is soft assertions, and why does it matter in TestNG?

Answer: soft assertions is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of soft assertions should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used soft assertions to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner10+ Years Frequently asked

6. What is expected exceptions, and why does it matter in TestNG?

Answer: expected exceptions is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of expected exceptions should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used expected exceptions to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner3 Years

7. How would you apply DataProvider in a production TestNG project?

Answer: Apply DataProvider through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that DataProvider controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused DataProvider check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing DataProvider.

Beginner3 Years

8. What is parameters, and why does it matter in TestNG?

Answer: parameters is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of parameters should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used parameters to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner3 Years

9. How would you apply dependsOnGroups in a production TestNG project?

Answer: Apply dependsOnGroups through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that dependsOnGroups controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused dependsOnGroups check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing dependsOnGroups.

Beginner5 Years

10. How would you apply thread count in a production TestNG project?

Answer: Apply thread count through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that thread count controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused thread count check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing thread count.

Beginner5 Years

11. What is listeners, and why does it matter in TestNG?

Answer: listeners is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of listeners should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used listeners to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner5 Years

12. How would you apply ITestContext in a production TestNG project?

Answer: Apply ITestContext through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that ITestContext controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused ITestContext check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing ITestContext.

Beginner7 Years

13. How would you apply suite XML in a production TestNG project?

Answer: Apply suite XML through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that suite XML controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused suite XML check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing suite XML.

Beginner7 Years

14. What is method interceptors, and why does it matter in TestNG?

Answer: method interceptors is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of method interceptors should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used method interceptors to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner7 Years

15. How would you apply timeouts in a production TestNG project?

Answer: Apply timeouts through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that timeouts controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused timeouts check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing timeouts.

Beginner10+ Years

16. How would you apply configuration failures in a production TestNG project?

Answer: Apply configuration failures through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that configuration failures controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused configuration failures check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing configuration failures.

Beginner10+ Years

17. What is alwaysRun, and why does it matter in TestNG?

Answer: alwaysRun is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of alwaysRun should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used alwaysRun to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

TestNG interview questions for experienced testers

Intermediate5 Years Frequently asked

18. How do you rerun only failed tests in TestNG?

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

Detailed explanation, example and interview tip

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.'

Intermediate5 Years Frequently asked

19. How do you run data-driven tests with @DataProvider, and when do you use an external file?

Answer: @DataProvider returns Object[][] (or an Iterator) that TestNG feeds into the test method once per row; move data to Excel/CSV/JSON when non-engineers own it or the set is large.

Detailed explanation, example and interview tip

Each row runs as a separate test with its own report entry, so a failure names the exact data set. Returning an Iterator<Object[]> streams rows lazily, which matters for thousands of records. parallel = true on the provider runs rows concurrently — only safe when the driver is ThreadLocal and the data rows are independent. Prefer typed model objects over raw strings so the test reads like a scenario rather than a column index lookup.

java
1@DataProvider(name = "invalidLogins", parallel = true)
2public Object[][] invalidLogins() {
3 return new Object[][] {
4 { "user@example.com", "", "Password is required" },
5 { "", "Secret123!", "Email is required" },
6 { "user@example.com", "wrong", "Invalid credentials" },
7 };
8}
9
10@Test(dataProvider = "invalidLogins")
11public void showsValidationError(String email, String password, String expected) {
12 loginPage.submit(email, password);
13 Assert.assertEquals(loginPage.errorMessage(), expected);
14}

Real-world example

Business analysts maintained 120 pricing combinations in a CSV that the provider streamed, so no code change was needed per new rule.

Interview tip

Say parallel data providers require thread-safe drivers — most candidates forget the coupling.

Intermediate3 Years Frequently asked

20. How would you apply annotation lifecycle in a production TestNG project?

Answer: Apply annotation lifecycle through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that annotation lifecycle controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused annotation lifecycle check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing annotation lifecycle.

Intermediate3 Years Frequently asked

21. How would you apply parameters in a production TestNG project?

Answer: Apply parameters through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that parameters controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused parameters check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing parameters.

Intermediate3 Years Frequently asked

22. What is dependsOnMethods, and why does it matter in TestNG?

Answer: dependsOnMethods is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of dependsOnMethods should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used dependsOnMethods to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate5 Years Frequently asked

23. How would you apply priority in a production TestNG project?

Answer: Apply priority through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that priority controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused priority check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing priority.

Intermediate5 Years Frequently asked

24. How would you apply listeners in a production TestNG project?

Answer: Apply listeners through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that listeners controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused listeners check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing listeners.

Intermediate5 Years Frequently asked

25. What is retry analyzer, and why does it matter in TestNG?

Answer: retry analyzer is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of retry analyzer should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used retry analyzer to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate7 Years Frequently asked

26. How would you apply soft assertions in a production TestNG project?

Answer: Apply soft assertions through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that soft assertions controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused soft assertions check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing soft assertions.

Intermediate7 Years Frequently asked

27. How would you apply method interceptors in a production TestNG project?

Answer: Apply method interceptors through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that method interceptors controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused method interceptors check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing method interceptors.

Intermediate7 Years Frequently asked

28. What is invocation count, and why does it matter in TestNG?

Answer: invocation count is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of invocation count should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used invocation count to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate10+ Years Frequently asked

29. How would you apply expected exceptions in a production TestNG project?

Answer: Apply expected exceptions through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that expected exceptions controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused expected exceptions check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing expected exceptions.

Intermediate10+ Years Frequently asked

30. How would you apply alwaysRun in a production TestNG project?

Answer: Apply alwaysRun through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that alwaysRun controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused alwaysRun check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing alwaysRun.

Intermediate10+ Years Frequently asked

31. What is data-provider parallelism, and why does it matter in TestNG?

Answer: data-provider parallelism is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of data-provider parallelism should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used data-provider parallelism to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate5 Years

32. What do TestNG listeners give you, and which ones do you actually implement?

Answer: ITestListener for screenshots/logging on failure, ISuiteListener for report lifecycle, IAnnotationTransformer for retries, and IInvokedMethodListener for per-step logging.

Detailed explanation, example and interview tip

Listeners keep cross-cutting concerns out of test code: nothing in a test should call the screenshot utility. ITestListener's onTestFailure is the single place to capture a screenshot, page source and console log, then attach them to the report. Registering listeners in testng.xml or with @Listeners keeps configuration declarative, and a ServiceLoader entry makes them apply everywhere without per-suite edits. Listeners run in the test thread, so anything shared inside them must be thread-safe.

java
1public class ReportListener implements ITestListener {
2 @Override public void onTestFailure(ITestResult result) {
3 WebDriver driver = DriverManager.get();
4 if (driver == null) return;
5 byte[] png = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
6 Allure.addAttachment(result.getName(), new ByteArrayInputStream(png));
7 Allure.addAttachment("url", driver.getCurrentUrl());
8 }
9
10 @Override public void onTestSkipped(ITestResult result) {
11 Reporter.log("Skipped: " + result.getName() + " -> " + result.getThrowable(), true);
12 }
13}

Real-world example

Adding URL plus browser console logs to failure attachments cut triage time on a 600-test suite from hours to minutes.

Interview tip

Emphasise 'no screenshot code inside tests' — clean separation is what is being assessed.

Intermediate3 Years

33. What is test groups, and why does it matter in TestNG?

Answer: test groups is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of test groups should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used test groups to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate5 Years

34. What is parallel modes, and why does it matter in TestNG?

Answer: parallel modes is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of parallel modes should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used parallel modes to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate7 Years

35. What is factories, and why does it matter in TestNG?

Answer: factories is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of factories should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used factories to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate10+ Years

36. What is reporters, and why does it matter in TestNG?

Answer: reporters is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of reporters should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used reporters to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced TestNG interview questions

Advanced7 Years Frequently asked

37. How do you configure parallel execution in TestNG?

Answer: Set parallel (methods, classes, tests or instances) plus thread-count in testng.xml, and make every shared resource thread-safe — driver in ThreadLocal, no static state, unique test data per thread.

Detailed explanation, example and interview tip

parallel='methods' gives the highest throughput but requires fully independent tests; 'classes' is the safest default when tests inside a class share setup. thread-count should map to available CPU and grid capacity — over-provisioning causes timeouts that look like product bugs. Data collisions are the other half of the problem: generate unique emails/order ids per thread rather than reusing fixtures. Reporting must also be thread-safe, which is why ExtentReports uses a ThreadLocal ExtentTest.

xml
1<suite name="regression" parallel="methods" thread-count="6" data-provider-thread-count="4">
2 <listeners>
3 <listener class-name="framework.listeners.RetryListener"/>
4 </listeners>
5 <test name="checkout">
6 <classes>
7 <class name="tests.CheckoutTest"/>
8 <class name="tests.PaymentTest"/>
9 </classes>
10 </test>
11</suite>

Real-world example

A nightly suite dropped from 2h to 25min at thread-count 6 once shared test users were replaced with per-thread generated accounts.

Interview tip

Frame it as 'parallelism is a data problem as much as a threading problem' — that is the senior answer.

Advanced3 Years Frequently asked

38. What is DataProvider, and why does it matter in TestNG?

Answer: DataProvider is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of DataProvider should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used DataProvider to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced5 Years Frequently asked

39. What is thread count, and why does it matter in TestNG?

Answer: thread count is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of thread count should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used thread count to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced7 Years Frequently asked

40. What is suite XML, and why does it matter in TestNG?

Answer: suite XML is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of suite XML should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used suite XML to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced10+ Years Frequently asked

41. What is configuration failures, and why does it matter in TestNG?

Answer: configuration failures is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of configuration failures should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used configuration failures to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced7 Years

42. How do you implement retry for flaky tests with IRetryAnalyzer, and when is it wrong?

Answer: Implement IRetryAnalyzer with a max-retry counter and attach it globally via an IAnnotationTransformer; use it for known infrastructure flakiness only, never to hide product bugs.

Detailed explanation, example and interview tip

Setting retryAnalyzer on every @Test does not scale, so a transformer applies it to the whole suite in one place. Keep the limit low (one or two) and always report that a test needed a retry, otherwise the suite quietly rots. Retries must be paired with a flakiness dashboard so the team fixes root causes; blanket retries turn a red suite green and destroy its signal. Tests that mutate data are often not safely retryable at all — the second attempt starts from a dirty state.

java
1public class Retry 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) {
7 count++;
8 Reporter.log("Retry " + count + " for " + result.getName(), true);
9 return true;
10 }
11 return false;
12 }
13}
14
15public class RetryTransformer implements IAnnotationTransformer {
16 @Override public void transform(ITestAnnotation ann, Class<?> c, Constructor<?> m, Method t) {
17 ann.setRetryAnalyzer(Retry.class);
18 }
19}

Real-world example

Retries hid a genuine race in a payments confirmation for weeks until retry counts were published per test and the top offender was fixed.

Interview tip

Say out loud 'retries are a monitoring tool, not a fix' — interviewers specifically probe for this.

Advanced3 Years

43. How would you apply test groups in a production TestNG project?

Answer: Apply test groups through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that test groups controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused test groups check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing test groups.

Advanced3 Years

44. How would you apply dependsOnMethods in a production TestNG project?

Answer: Apply dependsOnMethods through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that dependsOnMethods controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused dependsOnMethods check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing dependsOnMethods.

Advanced3 Years

45. What is dependsOnGroups, and why does it matter in TestNG?

Answer: dependsOnGroups is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of dependsOnGroups should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used dependsOnGroups to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced5 Years

46. How would you apply parallel modes in a production TestNG project?

Answer: Apply parallel modes through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that parallel modes controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused parallel modes check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing parallel modes.

Advanced5 Years

47. How would you apply retry analyzer in a production TestNG project?

Answer: Apply retry analyzer through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that retry analyzer controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused retry analyzer check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing retry analyzer.

Advanced5 Years

48. What is ITestContext, and why does it matter in TestNG?

Answer: ITestContext is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of ITestContext should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used ITestContext to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced7 Years

49. How would you apply factories in a production TestNG project?

Answer: Apply factories through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that factories controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused factories check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing factories.

Advanced7 Years

50. How would you apply invocation count in a production TestNG project?

Answer: Apply invocation count through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that invocation count controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused invocation count check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing invocation count.

Advanced7 Years

51. What is timeouts, and why does it matter in TestNG?

Answer: timeouts is a core TestNG concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of timeouts should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TestNG, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used timeouts to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced10+ Years

52. How would you apply reporters in a production TestNG project?

Answer: Apply reporters through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that reporters controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused reporters check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing reporters.

Advanced10+ Years

53. How would you apply data-provider parallelism in a production TestNG project?

Answer: Apply data-provider parallelism through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TestNG project, start by identifying the risk that data-provider parallelism controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused data-provider parallelism check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing data-provider parallelism.

Interview questions by subject

Want to search across every subject? Open the full question bank.