SoftwareTestPilot
28 TestNG Q&A

TestNG Interview Questions & Answers (2026)

28 real TestNG interview questions with senior-SDET answers and Java code — annotations, execution order, DataProvider, groups & priority, parallel runs, listeners, retry analyzers, and testng.xml suites.

  • 3 min read
  • Difficulty: Mixed (Easy → Medium)
  • Freshers → 5+ yrs
  • Updated July 2026
  • Avinash Kamble
TestNG Skill Track
Avinash Kamble
Founder & QA Engineer at SoftwareTestPilot
Published:
0 / 28 reviewed
0%

1. TestNG Basics

Easy Very Common 1 minQ1 / 28

Q1.What is TestNG?

Asked byAccentureCognizantHCLIBM
Why interviewers ask this

Interviewers open with "TestNG" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation

TestNG is a Java testing framework inspired by JUnit but designed for a wider range of test categories — unit, integration, end-to-end, and functional. It's the default runner for enterprise Selenium suites in 2026.

Tips to remember
  • Open with a one-sentence definition of TestNG, then a concrete TestNG example — never start with history or theory.
  • Keep the answer to 60–90 seconds; anything longer signals you can't summarise TestNG cleanly.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
RelatedQ3
Medium Very Common 1 minQ2 / 28

Q2.TestNG vs JUnit — key differences?

Asked byInfosysAccentureCognizantHCL
Why interviewers ask this

Comparison questions like this test whether you understand TestNG vs JUnit — key differences at a design level — not just that both exist, but when to pick one over the other. Panels use it to see if you can defend a trade-off with a real project example.

Detailed explanation
FeatureTestNGJUnit 5
Data providersNative @DataProvider@ParameterizedTest
GroupsYesTags only
DependenciesdependsOnMethodsNot supported
ParallelNative (XML)Native (properties)
ListenersRich setExtension model
Tips to remember
  • Structure the answer as a small table in your head: dimension, option A, option B — and close with "I'd pick X when Y".
  • Be ready to whiteboard the TestNG vs JUnit — key differences snippet live — panels often ask you to type it, not describe it.
  • Call out test isolation and shared-state risk (data, sessions, ports) before you talk about worker counts.
Medium Very Common 1 minQ3 / 28

Q3.How do you add TestNG to a Maven project?

Asked byHCLIBMTCSCapgemini
Why interviewers ask this

Hands-on "how would you add TestNG to a Maven project" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>7.10.2</version>
  <scope>test</scope>
</dependency>
Tips to remember
  • Walk through add TestNG to a Maven project as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the add TestNG to a Maven project snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Very Common 1 minQ4 / 28

Q4.What is a testng.xml file?

Asked byCognizantHCLIBMTCS
Why interviewers ask this

Interviewers open with "testng.xml file" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation

The suite configuration file. Defines which classes/methods run, in which order, parallel mode, groups, and parameters.

<suite name="Regression" parallel="tests" thread-count="4">
  <test name="Chrome">
    <parameter name="browser" value="chrome"/>
    <classes><class name="tests.LoginTest"/></classes>
  </test>
</suite>
Tips to remember
  • Open with a one-sentence definition of testng.xml file, then a concrete TestNG example — never start with history or theory.
  • Be ready to whiteboard the testng.xml file snippet live — panels often ask you to type it, not describe it.
  • Call out test isolation and shared-state risk (data, sessions, ports) before you talk about worker counts.
Medium Very Common 1 minQ5 / 28

Q5.How do you run a single test method?

Asked byTCSCapgeminiWiproInfosys
Why interviewers ask this

Hands-on "how would you run a single test method" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
mvn test -Dtest=LoginTest#validLogin
# or from testng.xml, use <methods><include name="validLogin"/></methods>
Tips to remember
  • Walk through run a single test method as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the run a single test method snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Confidence check

If you can confidently answer the TestNG Basics questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

2. Annotations & Lifecycle

Medium Very Common 1 minQ6 / 28

Q6.List the main TestNG annotations.

Asked byIBMTCSCapgeminiWipro
Why interviewers ask this

Listing questions on List the main TestNG annotations look easy but trap candidates who rattle off names without depth. Interviewers score higher when you group the items, mention which you use most, and add one line of context per item.

Detailed explanation
  • @Test, @BeforeSuite/@AfterSuite
  • @BeforeTest/@AfterTest
  • @BeforeClass/@AfterClass
  • @BeforeMethod/@AfterMethod
  • @DataProvider, @Parameters, @Listeners, @Factory
Tips to remember
  • Group the items into 2–3 categories before listing — panels remember structure, not raw counts.
  • Be ready to whiteboard the List the main TestNG annotations snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Very Common 1 minQ7 / 28

Q7.What's the execution order of the annotations?

Asked byWiproInfosysAccentureCognizant
Why interviewers ask this

This TestNG question checks whether you can go beyond textbook knowledge on What's the execution order of the annotations and reason about it the way a working QA engineer does — with a definition, an example, and the edge case that usually comes up next.

Detailed explanation

@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.

Tips to remember
  • Anchor the answer in a real TestNG project — panels reward specificity on What's the execution order of the annotations over textbook wording.
  • Be ready to whiteboard the What's the execution order of the annotations snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Very Common 1 minQ8 / 28

Q8.Difference between @BeforeTest and @BeforeMethod?

Asked byCapgeminiWiproInfosysAccenture
Why interviewers ask this

Comparison questions like this test whether you understand @BeforeTest vs @BeforeMethod at a design level — not just that both exist, but when to pick one over the other. Panels use it to see if you can defend a trade-off with a real project example.

Detailed explanation

@BeforeTest runs once per <test> block in the XML. @BeforeMethod runs before every single @Test method — used for per-test setup like opening a browser.

Tips to remember
  • Structure the answer as a small table in your head: dimension, option A, option B — and close with "I'd pick X when Y".
  • Be ready to whiteboard the @BeforeTest vs @BeforeMethod snippet live — panels often ask you to type it, not describe it.
  • Explain setup/teardown ordering and what runs per-test vs per-suite; ordering mistakes are the follow-up question.
Medium Very Common 1 minQ9 / 28

Q9.How do you skip a test conditionally?

Asked byAccentureCognizantHCLIBM
Why interviewers ask this

Hands-on "how would you skip a test conditionally" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
@Test
public void featureFlagged() {
  if (!Config.isEnabled("beta")) throw new SkipException("Beta off");
  // ...
}
Tips to remember
  • Walk through skip a test conditionally as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the skip a test conditionally snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Very Common 1 minQ10 / 28

Q10.What is a soft assertion?

Asked byInfosysAccentureCognizantHCL
Why interviewers ask this

Interviewers open with "soft assertion" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation
SoftAssert soft = new SoftAssert();
soft.assertEquals(title, "Home");
soft.assertTrue(banner.isDisplayed());
soft.assertAll(); // required, else failures are swallowed

Soft assertions collect failures and report all of them at the end.

Tips to remember
  • Open with a one-sentence definition of soft assertion, then a concrete TestNG example — never start with history or theory.
  • Be ready to whiteboard the soft assertion snippet live — panels often ask you to type it, not describe it.
  • Say who reads the report and what decision it drives — evidence-for-humans framing beats a tool name list.
Medium Very Common 1 minQ11 / 28

Q11.How do you use @Test attributes?

Asked byHCLIBMTCSCapgemini
Why interviewers ask this

Hands-on "how would you use @Test attributes" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
@Test(priority = 1, groups = {"smoke"}, timeOut = 5000,
      dependsOnMethods = "login", enabled = true,
      description = "Add to cart")
public void addToCart() { /* ... */ }
Tips to remember
  • Walk through use @Test attributes as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the use @Test attributes snippet live — panels often ask you to type it, not describe it.
  • Give the severity-vs-priority example from your own project — generic definitions score the lowest on this one.
Medium Common 1 minQ12 / 28

Q12.How do groups work?

Asked byCognizantHCLIBMTCS
Why interviewers ask this

Hands-on "how would you How do groups work" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
@Test(groups = {"smoke", "regression"})
public void t1() {}
<groups><run><include name="smoke"/></run></groups>
Tips to remember
  • Walk through How do groups work as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the How do groups work snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Confidence check

If you can confidently answer the Annotations & Lifecycle questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

3. Groups, Priority & Dependencies

Medium Common 1 minQ13 / 28

Q13.How do you set test priority?

Asked byTCSCapgeminiWiproInfosys
Why interviewers ask this

Hands-on "how would you set test priority" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation

@Test(priority = N) — lower N runs first. Ties are alphabetical. Don't rely on priority for real dependencies; use dependsOnMethods.

Tips to remember
  • Walk through set test priority as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the set test priority snippet live — panels often ask you to type it, not describe it.
  • Give the severity-vs-priority example from your own project — generic definitions score the lowest on this one.
Easy Common 1 minQ14 / 28

Q14.What does dependsOnMethods do?

Asked byIBMTCSCapgeminiWipro
Why interviewers ask this

This TestNG question checks whether you can go beyond textbook knowledge on What does dependsOnMethods do and reason about it the way a working QA engineer does — with a definition, an example, and the edge case that usually comes up next.

Detailed explanation

Ensures a prerequisite test passes before dependents run. If the parent fails, dependents are marked SKIPPED, not failed.

Tips to remember
  • Anchor the answer in a real TestNG project — panels reward specificity on What does dependsOnMethods do over textbook wording.
  • Keep the answer to 60–90 seconds; anything longer signals you can't summarise What does dependsOnMethods do cleanly.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Common 1 minQ15 / 28

Q15.How do you retry failed tests?

Asked byWiproInfosysAccentureCognizant
Why interviewers ask this

Hands-on "how would you retry failed tests" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
public class Retry implements IRetryAnalyzer {
  int count = 0, max = 2;
  public boolean retry(ITestResult r) { return count++ < max; }
}
@Test(retryAnalyzer = Retry.class) public void flaky() {}
Tips to remember
  • Walk through retry failed tests as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the retry failed tests snippet live — panels often ask you to type it, not describe it.
  • Quote a real flake-rate number before and after your fix; measured outcomes score far higher than "we added retries".
Medium Common 1 minQ16 / 28

Q16.What is IAnnotationTransformer used for?

Asked byCapgeminiWiproInfosysAccenture
Why interviewers ask this

Interviewers open with "IAnnotationTransformer" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation

To programmatically apply annotations at load time — e.g. attach a Retry analyzer to every @Test without editing each class.

Tips to remember
  • Open with a one-sentence definition of IAnnotationTransformer, then a concrete TestNG example — never start with history or theory.
  • Be ready to whiteboard the IAnnotationTransformer snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Common 1 minQ17 / 28

Q17.How do you set a global timeout?

Asked byAccentureCognizantHCLIBM
Why interviewers ask this

Hands-on "how would you set a global timeout" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation

Per test: @Test(timeOut = 5000). Suite-wide: <suite time-out="5000"> in testng.xml.

Tips to remember
  • Walk through set a global timeout as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the set a global timeout snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Common 1 minQ18 / 28

Q18.How do you handle expected exceptions?

Asked byInfosysAccentureCognizantHCL
Why interviewers ask this

Hands-on "how would you handle expected exceptions" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
@Test(expectedExceptions = IllegalArgumentException.class,
       expectedExceptionsMessageRegExp = "id.*required")
public void invalidInput() { service.create(null); }
Tips to remember
  • Walk through handle expected exceptions as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the handle expected exceptions snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Confidence check

If you can confidently answer the Groups, Priority & Dependencies questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

4. DataProvider & Parameterization

Medium Common 1 minQ19 / 28

Q19.What is @DataProvider?

Asked byHCLIBMTCSCapgemini
Why interviewers ask this

Interviewers open with "@DataProvider" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation
@DataProvider(name = "logins")
public Object[][] logins() {
  return new Object[][]{ {"a@x.com","p1"}, {"b@x.com","p2"} };
}
@Test(dataProvider = "logins")
public void login(String email, String pwd) { /* ... */ }
Tips to remember
  • Open with a one-sentence definition of @DataProvider, then a concrete TestNG example — never start with history or theory.
  • Be ready to whiteboard the @DataProvider snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Common 1 minQ20 / 28

Q20.How do you read test data from Excel/CSV?

Asked byCognizantHCLIBMTCS
Why interviewers ask this

Hands-on "how would you read test data from Excel/CSV" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation

Read the file inside the @DataProvider and return Object[][]. Popular libs: Apache POI (Excel), OpenCSV (CSV), Jackson (JSON).

Tips to remember
  • Walk through read test data from Excel/CSV as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the read test data from Excel/CSV snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Occasional 1 minQ21 / 28

Q21.Difference between @Parameters and @DataProvider?

Asked byTCSCapgeminiWiproInfosys
Why interviewers ask this

Comparison questions like this test whether you understand @Parameters vs @DataProvider at a design level — not just that both exist, but when to pick one over the other. Panels use it to see if you can defend a trade-off with a real project example.

Detailed explanation

@Parameters reads static values from testng.xml (like browser name). @DataProvider supplies dynamic in-code datasets and drives multiple iterations of one test.

Tips to remember
  • Structure the answer as a small table in your head: dimension, option A, option B — and close with "I'd pick X when Y".
  • Be ready to whiteboard the @Parameters vs @DataProvider snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Occasional 1 minQ22 / 28

Q22.How do you pass parameters from testng.xml?

Asked byIBMTCSCapgeminiWipro
Why interviewers ask this

Hands-on "how would you pass parameters from testng.xml" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
<parameter name="browser" value="chrome"/>
@Test @Parameters("browser")
public void open(String browser) { /* ... */ }
Tips to remember
  • Walk through pass parameters from testng.xml as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the pass parameters from testng.xml snippet live — panels often ask you to type it, not describe it.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Confidence check

If you can confidently answer the DataProvider & Parameterization questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

5. Parallel, Listeners & XML

Medium Occasional 1 minQ23 / 28

Q23.How do you run tests in parallel?

Asked byWiproInfosysAccentureCognizant
Why interviewers ask this

Hands-on "how would you run tests in parallel" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
<suite name="R" parallel="methods" thread-count="8">

Values: tests, classes, methods, instances. Combine with a ThreadLocal<WebDriver> to keep browser instances isolated.

Tips to remember
  • Walk through run tests in parallel as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the run tests in parallel snippet live — panels often ask you to type it, not describe it.
  • Call out test isolation and shared-state risk (data, sessions, ports) before you talk about worker counts.
Medium Occasional 1 minQ24 / 28

Q24.What is a Listener?

Asked byCapgeminiWiproInfosysAccenture
Why interviewers ask this

Interviewers open with "Listener" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation

An interface that hooks into TestNG events. Implement ITestListener to add screenshots on failure, Extent Report entries, or Slack notifications.

@Listeners(ScreenshotListener.class)
public class BaseTest {}
Tips to remember
  • Open with a one-sentence definition of Listener, then a concrete TestNG example — never start with history or theory.
  • Be ready to whiteboard the Listener snippet live — panels often ask you to type it, not describe it.
  • Explain setup/teardown ordering and what runs per-test vs per-suite; ordering mistakes are the follow-up question.
Easy Occasional 1 minQ25 / 28

Q25.What is @Factory?

Asked byAccentureCognizantHCLIBM
Why interviewers ask this

Interviewers open with "@Factory" to confirm you can define the concept in one crisp line before going deeper. In TestNG rounds this filters out candidates who only remember syntax and can't articulate the underlying idea to a non-expert teammate.

Detailed explanation

Creates test class instances at runtime — useful when the same tests need to run for many test-data rows or configurations.

Tips to remember
  • Open with a one-sentence definition of @Factory, then a concrete TestNG example — never start with history or theory.
  • Keep the answer to 60–90 seconds; anything longer signals you can't summarise @Factory cleanly.
  • Know the annotation execution order cold — it's the follow-up in almost every TestNG round.
Medium Occasional 1 minQ26 / 28

Q26.How do you integrate TestNG with Selenium POM?

Asked byInfosysAccentureCognizantHCL
Why interviewers ask this

Hands-on "how would you integrate TestNG with Selenium POM" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation

Extend a BaseTest that has @BeforeMethod to launch the browser and @AfterMethod to quit it. Page objects are instantiated inside tests. See our POM guide (concepts translate to Java).

Tips to remember
  • Walk through integrate TestNG with Selenium POM as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the integrate TestNG with Selenium POM snippet live — panels often ask you to type it, not describe it.
  • Add one sentence on what does NOT belong in a page object (assertions, test data) — that boundary is what separates mid from senior answers.
Medium Occasional 1 minQ27 / 28

Q27.How do you generate reports?

Asked byHCLIBMTCSCapgemini
Why interviewers ask this

Hands-on "how would you generate reports" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation

Default: test-output/emailable-report.html. Popular add-ons: ExtentReports, Allure, ReportPortal. Wire them via a Listener.

Tips to remember
  • Walk through generate reports as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the generate reports snippet live — panels often ask you to type it, not describe it.
  • Say who reads the report and what decision it drives — evidence-for-humans framing beats a tool name list.
Medium Occasional 1 minQ28 / 28

Q28.How do you integrate TestNG with Jenkins/GitHub Actions?

Asked byCognizantHCLIBMTCS
Why interviewers ask this

Hands-on "how would you integrate TestNG with Jenkins/GitHub Actions" questions reveal whether you've actually shipped TestNG code or only read about it. Interviewers listen for concrete steps, the tools you'd reach for first, and the failure mode you'd guard against.

Detailed explanation
- run: mvn -B test -DsuiteXmlFile=testng.xml
- uses: actions/upload-artifact@v4
  if: always()
  with: { name: reports, path: test-output/ }
Tips to remember
  • Walk through integrate TestNG with Jenkins/GitHub Actions as numbered steps and call out the tool, command, or API used at each step.
  • Be ready to whiteboard the integrate TestNG with Jenkins/GitHub Actions snippet live — panels often ask you to type it, not describe it.
  • Describe the pipeline stage order and what makes the build fail — a vague "we run tests in CI" answer stalls here.
RelatedQ26
Confidence check

If you can confidently answer the Parallel, Listeners & XML questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

Quick revision

  1. Q1: What is TestNG — TestNG is a Java testing framework inspired by JUnit but designed for a wider range of test categories — unit, integration, end-to-end, and functional.
  2. Q2: TestNG vs JUnit — key differences — Feature TestNG JUnit 5 Data providers Native @DataProvider @ParameterizedTest Groups Yes Tags only Dependencies dependsOnMethods Not supported Parallel Native (XML) Native (propert
  3. Q3: How do you add TestNG to a Maven project — &lt;dependency&gt; &lt;groupId&gt;org.testng&lt;/groupId&gt; &lt;artifactId&gt;testng&lt;/artifactId&gt; &lt;version&gt;7.10.2&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/
  4. Q4: What is a testng.xml file — The suite configuration file.
  5. Q5: How do you run a single test method — mvn test -Dtest=LoginTest#validLogin # or from testng.xml, use &lt;methods&gt;&lt;include name="validLogin"/&gt;&lt;/methods&gt;

Frequently asked questions

1.Is TestNG still used in 2026?
Yes — it's still the default runner for Java Selenium and REST Assured suites. JUnit 5 is catching up but TestNG dominates enterprise QA jobs.
2.Should I learn TestNG or JUnit first?
If you're doing Selenium/Java automation, learn TestNG first — it maps 1:1 to what most QA jobs use. Add JUnit 5 later.
3.Can TestNG run in parallel with a ThreadLocal WebDriver?
Yes. Store the driver in ThreadLocal<WebDriver>, initialize in @BeforeMethod, tear down in @AfterMethod, set parallel='methods' in testng.xml.
4.What version of TestNG should I use?
Use 7.10+ (Java 11+ required). Older 6.x still works but misses newer annotations and native soft-assert improvements.

TestNG jobs hiring now

Live, indexable TestNG openings — updated daily in Jobs Radar.

Browse all QA jobs on Jobs Radar

Loading current openings…

Home