TestNG interview questions test Java automation skill across annotations, suites, groups, dependencies, data providers, parallel execution, listeners, assertions, and reporting.
45 questions with answersKey Takeaways
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.
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.
Start here. These are the definitions and first-principle checks that open most rounds.
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)
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.
@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.
@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 part | What to say | Evidence to mention |
|---|---|---|
| Definition | @BeforeMethod in one direct sentence. | Official docs or course material |
| Use case | The work where it changes a decision. | Dataset, model, query, dashboard, or pipeline |
| Risk | What breaks when it is misunderstood. | Metric, log, test result, or review note |
@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)
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
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.
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.
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.
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.
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.
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.
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)
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.
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.
These questions test whether you can apply the topic to real data, real code, and messy constraints.
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.
import org.testng.Assert;
import org.testng.annotations.Test;
public class CalculatorTest {
@Test
public void addsTwoNumbers() {
Assert.assertEquals(2 + 3, 5);
}
}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.
@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);
}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.
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.
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.
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.
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.
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.
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.
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)
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.
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.
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.
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.
Advanced rounds test trade-offs, failure modes, and whether the decision can hold up under production pressure.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
TestNG is often mentioned with Selenium, but they solve different problems. Selenium controls browsers. TestNG organizes and runs the tests.
| Tool | Main purpose | Common interview topic | Mistake to avoid |
|---|---|---|---|
| TestNG | Test runner and framework for Java | Annotations, XML, groups, DataProvider, listeners | Treating it as a browser tool |
| JUnit | Java test framework | Assertions, lifecycle, extensions | Assuming every Java project uses TestNG |
| Selenium | Browser automation | Locators, waits, WebDriver, Grid | Mixing WebDriver setup into every test |
| Maven Surefire | Build-time test execution | Running tests in CI | Ignoring 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.
Prepare by writing a tiny Selenium Java suite with TestNG. Include annotations, a DataProvider, groups, testng.xml, a listener, and one parallel run.
TestNG framework flow
A TestNG answer should show suite design, not just annotation names.
Strong TestNG answers show that you can keep Java automation organized as the suite grows. the check is structure, isolation, and CI signal.
| Topic | Weak answer | Strong answer |
|---|---|---|
| Annotations | I know @Test. | I explain lifecycle and where setup, cleanup, and assertions belong. |
| Parallel | Set parallel=true. | Use isolated driver, data, and state so threads do not collide. |
| DataProvider | It runs data. | It feeds test cases clearly and can run in parallel with thread control. |
| Listeners | For reports. | Capture failure evidence, screenshots, logs, and status without hiding assertions. |
6 questions, about 4 minutes. Score 70% or higher to earn a shareable certificate.
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