Core automation track

TestNG

The execution engine behind grouping, data driving and parallel runs.

What this track covers

Annotations & lifecycleAssertions & SoftAssertGroupsDataProviderParametersDependenciesListenersRetry AnalyzerTestNG XMLParallel executionRerun failed tests

Parallel execution done safely

TestNG creates threads; your framework must guarantee that nothing mutable is shared between them.

Why it is required: Parallel execution is the single biggest lever on suite runtime — and the biggest source of flakiness when done wrong.

Example: parallel="classes" with a ThreadLocal driver and per-test data seeding.

xml
1<suite name="regression" parallel="classes" thread-count="6">
2 <test name="web">
3 <parameter name="browser" value="chrome"/>
4 <classes>
5 <class name="com.sdet.tests.LoginTest"/>
6 <class name="com.sdet.tests.CheckoutTest"/>
7 </classes>
8 </test>
9</suite>

Expected result

Six browser sessions running independently with isolated drivers and data.

Common mistakes

  • static WebDriver shared across threads
  • parallel="methods" with class-level state
  • Shared login account across threads

How do you make WebDriver thread-safe?

Related interview questions

Open bank
  • How do you rerun only failed tests in TestNG?

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

  • DataProvider vs @Parameters — when do you use each?

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

  • In what order do TestNG annotations execute?

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

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

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

  • How do you configure parallel execution in TestNG?

    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.

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

    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.

Quick reference available

Open the matching cheat sheet for last-minute revision.