TestNG Interview Questions (2026)

TestNG interview questions test Java automation skill across annotations, suites, groups, dependencies, data providers, parallel execution, listeners, assertions, and reporting.

45 questions with answers

What Is TestNG?

Key Takeaways

  • TestNG is a Java testing framework often used with Selenium automation projects.
  • Interviewers ask about annotations, testng.xml, groups, priorities, dependencies, parameters, DataProvider, listeners, and parallel runs.
  • Strong answers explain test isolation, thread safety, reporting, and why framework code must stay readable.
  • TestNG can run unit, integration, API, and UI tests, but it is most often discussed in Selenium Java automation interviews.

TestNG is a Java testing framework used to organize and run automated tests. It gives teams annotations, suite configuration, grouping, dependencies, data providers, parallel execution, listeners, and reporting hooks. In interviews, TestNG questions check whether you can structure a Java automation suite that is readable, repeatable, and safe to run in CI.

45TestNG questions with direct answers
JavaPrimary ecosystem
XMLCommon suite configuration
ParallelFrequent senior topic

Watch: Understanding and Creating TestNG.xml file for Tests

Video: Understanding and Creating TestNG.xml file for Tests (Naveen AutomationLabs, YouTube)

Test yourself and earn a certificate

6 quick questions. Score 70%+ to download your TestNG certificate.

Jump to quiz

All Questions on This Page

45 questions
TestNG Advanced Scenarios
  1. 31. Parallel tests fail when using one static WebDriver. What is wrong?
  2. 32. A suite has long dependsOnMethods chains. What is the risk?
  3. 33. DataProvider runs in parallel and tests collide. What do you inspect?
  4. 34. A listener catches an exception and the test passes. What is wrong?
  5. 35. Tests pass only when priority order is kept. What does that signal?
  6. 36. CI runs a different group than local runs. What do you check?
  7. 37. The team retries every failed test three times. What is the risk?
  8. 38. Tests fail after earlier tests create data. What do you change?
  9. 39. A project has smoke, Smoke, and SMOKE groups. What do you improve?
  10. 40. A TestNG suite is too slow. What do you do?
  11. 41. A TestNG Selenium test only clicks screens. What is missing?
  12. 42. @BeforeMethod fails. What happens?
  13. 43. A browser parameter is misspelled in XML. What should happen?
  14. 44. CI says suite failed but no test details. What do you improve?
  15. 45. What makes a TestNG answer senior?

TestNG Fundamentals

Foundational15 questions

Start here. These are the definitions and first-principle checks that open most rounds.

Q1. What is TestNG?

TestNG is a Java testing framework used to organize, configure, run, and report automated tests.

It is common in Selenium Java automation projects.

TestNG changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Watch a deeper explanation

Video: Run a Test in Parallel Using TestNG Data Provider (Automation Step by Step, YouTube)

Q2. What are TestNG annotations?

Annotations mark test methods and lifecycle methods such as setup and cleanup.

They let TestNG decide when each method runs.

annotation changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q3. What does @Test do?

@Test marks a method as a test method that TestNG should execute.

Attributes can define groups, dependencies, priority, timeouts, and data providers.

@Test changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q4. When do you use @BeforeMethod?

@BeforeMethod runs before each test method.

Use it for per-test setup such as fresh driver state or test data.

@BeforeMethod changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Answer partWhat to sayEvidence to mention
Definition@BeforeMethod in one direct sentence.Official docs or course material
Use caseThe work where it changes a decision.Dataset, model, query, dashboard, or pipeline
RiskWhat breaks when it is misunderstood.Metric, log, test result, or review note

Q5. Why use @AfterMethod?

@AfterMethod runs after each test method.

Use it for cleanup, driver quit, screenshot capture, or result-based actions.

@AfterMethod changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Watch a deeper explanation

Video: DataProvider in TestNG (RCV Academy, YouTube)

Q6. What is testng.xml?

testng.xml configures suites, tests, classes, groups, parameters, and parallel execution.

It lets teams run selected test sets without changing code.

testng.xml changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

testng.xml execution flow

1Suite
top-level run
2Test
named group of classes
3Class
test classes
4Method
selected tests

Q7. What is a suite in TestNG?

A suite is a top-level collection of tests defined in XML or runtime configuration.

Suites are often used for smoke, regression, or browser-specific runs.

suite changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q8. What are groups in TestNG?

Groups label tests so they can be included or excluded from a run.

Examples include smoke, regression, api, ui, slow, and critical.

groups changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q9. What does priority do in TestNG?

Priority controls execution order when TestNG needs to order test methods.

Avoid building suites that depend heavily on priority.

priority changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q10. What is dependsOnMethods?

dependsOnMethods makes a test depend on another test method's success.

Use it carefully because dependencies can make suites brittle.

dependsOnMethods changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q11. What is DataProvider?

DataProvider supplies multiple sets of data to a test method.

It is useful for data-driven checks.

DataProvider changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q12. How are TestNG parameters used?

Parameters pass values from XML into test methods or setup methods.

They are often used for browser, environment, or base URL values.

parameters changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q13. What are TestNG listeners?

Listeners hook into test execution events such as start, success, failure, and finish.

They are useful for reports, screenshots, logs, and custom output.

listeners changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Watch a deeper explanation

Video: Parallel Testing in TestNG (TestMu AI, YouTube)

Q14. What assertions are used in TestNG?

TestNG assertions verify expected outcomes and fail tests when expectations are not met.

Assertions should prove behavior, not just page movement.

assertions changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q15. What is parallel execution in TestNG?

Parallel execution runs tests across multiple threads using XML or configuration settings.

It needs thread-safe driver and data handling.

parallel execution changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Back to question list

TestNG Practical Interview Questions

Intermediate15 questions

These questions test whether you can apply the topic to real data, real code, and messy constraints.

Q16. Show a basic TestNG test.

Create a method with @Test and assert the expected result.

Keep the assertion focused.

write basic TestNG test changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

java
import org.testng.Assert;
import org.testng.annotations.Test;

public class CalculatorTest {
  @Test
  public void addsTwoNumbers() {
    Assert.assertEquals(2 + 3, 5);
  }
}

Q17. How do you write a data-driven TestNG test?

Create a DataProvider that returns input rows, then reference it from @Test.

The data sets clearly.

use DataProvider changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

java
@DataProvider(name = "loginData")
public Object[][] loginData() {
  return new Object[][] {{"valid@site.com", "secret"}, {"locked@site.com", "secret"}};
}

@Test(dataProvider = "loginData")
public void loginCases(String email, String password) {
  Assert.assertNotNull(email);
}

Q18. How do you configure tests in testng.xml?

Define suite, test, classes, methods, parameters, groups, and parallel settings as needed.

Keep XML files understandable and source controlled.

configure XML suite changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q19. How do you run only smoke tests?

Assign tests to a smoke group and include that group in XML or runner configuration.

Groups make CI jobs smaller and faster.

run smoke group changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q20. How do you run Selenium tests in parallel with TestNG?

Use ThreadLocal WebDriver, isolated data, separate browser sessions, and controlled thread count.

One shared static driver will break parallel runs.

parallel Selenium tests changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q21. How do you capture screenshots on failure?

Use a listener or @AfterMethod with test result status to capture evidence from the active driver.

Attach build, browser, and test name with the screenshot.

capture screenshot on failure changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q22. When would you use dependsOnMethods?

Use it only when one test genuinely cannot run unless another setup-like test passes.

Prefer independent tests when possible.

handle dependencies changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q23. How do you pass browser name to tests?

Define a parameter in XML and read it in setup with @Parameters.

Validate values so bad config fails clearly.

use parameters changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q24. What would you put in a TestNG listener?

Log test start, success, failure, skipped status, screenshots, retries, and report metadata.

Listeners should not swallow failures.

build listener changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q25. How do you retry failed tests?

Use a retry analyzer with strict limits and track retries separately.

Retries are for noisy infrastructure, not product defects.

retry failed tests changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Watch a deeper explanation

Video: TestNG XML File (Naveen AutomationLabs, YouTube)

Q26. How do you run TestNG tests in Maven?

Configure Surefire or Failsafe with the TestNG suite XML or included groups.

The build tool decides what CI actually runs.

run in Maven changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q27. How do you avoid shared state in TestNG?

Create per-test setup, use local variables, ThreadLocal where needed, and avoid mutable static fields.

Shared state is the main parallel execution risk.

avoid shared state changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q28. What reporting options do TestNG projects use?

Use default reports, listeners, Extent-style reports, Allure-style reports, or CI reports depending on team needs.

Reports should support triage, not just look polished.

generate reports changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q29. How should priority be used?

Use priority sparingly for ordering when required, but design tests to be independent.

Heavy priority use often hides coupling.

prioritize tests changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q30. What do you review in a TestNG framework?

Check lifecycle setup, driver management, data isolation, grouping, reporting, retry policy, and CI command.

Framework health is visible in failure diagnosis.

review framework changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Back to question list

TestNG Advanced Scenarios

Advanced15 questions

Advanced rounds test trade-offs, failure modes, and whether the decision can hold up under production pressure.

Q31. Parallel tests fail when using one static WebDriver. What is wrong?

The driver is shared across threads.

Use ThreadLocal or create isolated driver instances per test.

shared WebDriver changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q32. A suite has long dependsOnMethods chains. What is the risk?

One early failure can skip many tests and hide independent results.

Prefer independent tests and setup methods.

depends chain changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q33. DataProvider runs in parallel and tests collide. What do you inspect?

Check shared users, mutable objects, static state, and data-provider thread count.

Data rows still need isolation.

DataProvider collision changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q34. A listener catches an exception and the test passes. What is wrong?

The listener is masking a real failure.

Failure capture should record evidence, not change test truth.

listener hides failure changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q35. Tests pass only when priority order is kept. What does that signal?

Tests depend on hidden state or order.

Make setup explicit and tests independent.

priority order bug changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q36. CI runs a different group than local runs. What do you check?

Check testng.xml, Maven config, CI command, profile, and group names.

Runner configuration is part of test code.

XML drift changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q37. The team retries every failed test three times. What is the risk?

Real product failures and flaky test patterns are hidden.

Track retries and fix root causes.

retry abuse changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q38. Tests fail after earlier tests create data. What do you change?

Add cleanup, unique data, or reset state per test.

TestNG lifecycle hooks can help, but the data model matters.

missing cleanup changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q39. A project has smoke, Smoke, and SMOKE groups. What do you improve?

Standardize group names and document allowed groups.

Inconsistent tags make CI selection unreliable.

group naming mess changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q40. A TestNG suite is too slow. What do you do?

Split smoke from regression, parallelize safely, move checks lower, and remove duplicate UI paths.

Speed should not create false signal.

slow suite changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q41. A TestNG Selenium test only clicks screens. What is missing?

It needs assertions that prove business outcome.

Runner success is not product validation.

no assertion changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q42. @BeforeMethod fails. What happens?

The related test is skipped or failed based on configuration and failure handling.

Setup failures should be clear in reports.

setup failure changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q43. A browser parameter is misspelled in XML. What should happen?

Setup should fail fast with a clear message.

Bad config should not create confusing test errors.

browser parameter error changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q44. CI says suite failed but no test details. What do you improve?

Publish XML reports, screenshots, logs, and a readable summary.

Automation must produce actionable evidence.

CI report unclear changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Q45. What makes a TestNG answer senior?

It covers lifecycle, runner config, data isolation, parallel safety, reporting, retries, and CI command clarity.

Senior candidates care about signal trust.

senior TestNG answer changes TestNG decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.

Back to question list

TestNG vs JUnit vs Selenium

TestNG is often mentioned with Selenium, but they solve different problems. Selenium controls browsers. TestNG organizes and runs the tests.

ToolMain purposeCommon interview topicMistake to avoid
TestNGTest runner and framework for JavaAnnotations, XML, groups, DataProvider, listenersTreating it as a browser tool
JUnitJava test frameworkAssertions, lifecycle, extensionsAssuming every Java project uses TestNG
SeleniumBrowser automationLocators, waits, WebDriver, GridMixing WebDriver setup into every test
Maven SurefireBuild-time test executionRunning tests in CIIgnoring build runner configuration

TestNG interview topic weight

Most TestNG rounds are Java automation framework discussions.

Scale: Hyring editorial score for interview preparation, not an external benchmark.

Annotations
88 weight
DataProvider
84 weight
Parallel
82 weight
Priority
48 weight
  • Annotations: lifecycle and order
  • DataProvider: data-driven tests
  • Parallel: thread safety
  • Priority: limited use

How to Prepare for a TestNG Interview

Prepare by writing a tiny Selenium Java suite with TestNG. Include annotations, a DataProvider, groups, testng.xml, a listener, and one parallel run.

  • Know before, after, test, parameters, DataProvider, groups, dependsOnMethods, priority, listeners, and assertions.
  • Practice reading and writing a testng.xml file with suites, tests, classes, methods, groups, and parameters.
  • Prepare a parallel execution answer: isolated WebDriver, ThreadLocal, separate data, and no shared mutable state.
  • Explain how TestNG runs in Maven or CI and where reports and screenshots are attached.

TestNG framework flow

1Structure
classes, annotations, groups
2Feed data
parameters or DataProvider
3Run safely
XML, Maven, CI, parallel
4Report
listeners, screenshots, logs

A TestNG answer should show suite design, not just annotation names.

What Strong TestNG Answers Prove

Strong TestNG answers show that you can keep Java automation organized as the suite grows. the check is structure, isolation, and CI signal.

TopicWeak answerStrong answer
AnnotationsI know @Test.I explain lifecycle and where setup, cleanup, and assertions belong.
ParallelSet parallel=true.Use isolated driver, data, and state so threads do not collide.
DataProviderIt runs data.It feeds test cases clearly and can run in parallel with thread control.
ListenersFor reports.Capture failure evidence, screenshots, logs, and status without hiding assertions.

Test Yourself: TestNG Quiz

Ready to test your TestNG knowledge?

6 questions, about 4 minutes. Score 70% or higher to earn a shareable certificate.

6 questions Instant feedback Free certificate on 70%+

Frequently  Asked  Questions

What do TestNG interviews usually ask?

They ask about annotations, testng.xml, DataProvider, groups, parameters, dependencies, listeners, assertions, parallel execution, and CI reports. Complete coverage has one concrete example, one failure case, and one validation signal beyond the definition.

Is TestNG only used with Selenium?

No. TestNG can run many kinds of Java tests, but interviews often discuss it with Selenium Java automation.

How do I explain parallel execution in TestNG?

Explain XML parallel settings, thread count, isolated WebDriver, isolated data, no mutable static state, and clear reports. Complete coverage has one concrete example, one failure case, and one validation signal beyond the definition.

What TestNG project should I discuss?

Use a project with groups, DataProvider, XML suites, listener-based screenshots, Maven or CI execution, and a flake fix story.

What is the biggest TestNG interview mistake?

Listing annotations without explaining suite design, isolation, and reporting. the question needs to know how your framework behaves under real CI runs.

Is there a TestNG quiz?

Yes. The quiz checks DataProvider, XML suites, parallel safety, listeners, and common framework mistakes. Complete coverage has one concrete example, one failure case, and one validation signal beyond the definition.

Practice Java automation answers

Hyring's AI Coding Interviewer can score Java test code and explanation together. Use this page first, then rehearse TestNG, Selenium, and framework design answers.

Try AI coding interview prep

Sources

Adithyan RKWritten by Adithyan RK
Surya N
Fact-checked by Surya N
Published on: 19 Apr 2026Last updated: 6 Jul 2026
Share: