Resource library

Automation Interview

TestNG Interview Questions and Answers (2026)

Prepare testng interview questions and answers with practical lifecycle, DataProvider, parallelism, listeners, suite XML, debugging, and model responses.

24 min read | 3,070 words

TL;DR

TestNG interviews evaluate whether you can design, run, and debug reliable Java tests. Prepare the annotation lifecycle, DataProviders, groups, dependencies, parallel execution, listeners, retries, suite XML, build integration, and clear examples of failure classification and resource cleanup.

Key Takeaways

  • Explain TestNG through execution lifecycle and test design, not as a memorized annotation list.
  • Know configuration scope, inheritance, `alwaysRun`, dependencies, groups, parameters, and DataProviders with concrete examples.
  • Treat parallel execution as an isolation problem involving driver, data, files, and reporting state.
  • Use listeners for observation, retry analyzers for narrow transient policy, and suite XML for explicit execution composition.
  • Be ready to code a small DataProvider test and diagnose a failed configuration or flaky parallel scenario.
  • Strong senior answers discuss tradeoffs, evidence, cleanup, and CI behavior instead of claiming one universal framework pattern.

Testng interview questions and answers are easiest to master when you understand the runner as a lifecycle, not when you memorize isolated annotations. A strong candidate can predict what TestNG will discover, which configuration will run, how data and threads are assigned, what happens after failure, and how the result reaches CI.

This guide covers the questions interviewers use from junior through senior automation roles. It includes runnable Java, decision tables, debugging scenarios, and model answers you can adapt to work you genuinely understand.

TL;DR

Interview area What you should demonstrate
Lifecycle Correct scope and order of suite, test, class, method, and test callbacks
Test design Independent cases, useful assertions, explicit setup and cleanup
Data Typed @DataProvider rows and safe parallel fixtures
Selection Groups, include and exclude rules, parameters, and suite XML
Parallelism Session, data, file, and listener isolation
Extension Listeners, reporters, annotation transformers, and retry policy
Delivery Maven or Gradle execution, reports, exit status, and CI artifacts
Debugging Evidence-based classification of product, test, data, and environment failures

Prepare a two-minute framework explanation, one DataProvider coding exercise, one parallel failure story, and one listener or retry design. Interviewers usually probe your decisions after the first definition.

1. TestNG Interview Questions and Answers: What Interviewers Measure

TestNG is a Java testing framework with annotations, configuration lifecycles, groups, parameters, DataProviders, dependencies, factories, listeners, parallel execution, and report integration. Saying only that it is better than JUnit is a weak answer. Current JUnit also supports rich lifecycle and extensions. Explain why the team selected TestNG for its suite composition, data model, listener ecosystem, or existing framework conventions.

At junior level, interviewers expect correct annotations, assertions, test priority, enablement, and basic suite XML. At mid level, they add DataProviders, groups, parameters, dependencies, Maven execution, screenshots, and failed-test diagnosis. Senior candidates should discuss thread safety, retries, configuration failure, custom listeners, report integrity, framework ownership, and CI scaling.

For every concept, connect definition to a risk. @BeforeMethod provides per-case setup, which improves isolation but can add cost. A parallel DataProvider reduces duration only if rows use independent records and the environment has capacity. A retry may classify a transient failure, but a blanket retry can hide a race.

Use accurate ownership language. If you added pages and listeners to an existing framework, say that. Describe the problem, implementation, verification, and tradeoff. A practical explanation is more credible than claiming you built everything from scratch.

When comparing frameworks, use the TestNG vs JUnit 5 guide and focus on project fit rather than a winner.

2. Annotation Lifecycle and Configuration Scope

The common configuration sequence is @BeforeSuite, @BeforeTest, @BeforeClass, @BeforeMethod, test method, then the corresponding after annotations in reverse scope. Here, @BeforeTest refers to a <test> element in testng.xml, not one Java @Test method. That distinction is a frequent interview check.

Configuration inheritance matters. TestNG honors configuration methods declared in superclasses. Before methods run from the highest superclass toward the subclass. After methods run in reverse. This supports a small base fixture, but deep inheritance can hide resources and ordering. Prefer composition for services that do not require annotation inheritance.

alwaysRun = true has context-dependent meaning. On after configuration methods, it helps cleanup run despite earlier failure or group restrictions. On before configuration methods, it affects group behavior, but it cannot guarantee execution after every possible process termination. Explain the scenario rather than saying it means always under all conditions.

package example.lifecycle;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class LifecycleExample {
    @BeforeClass
    public void createApiClient() {
        System.out.println("once for this class instance");
    }

    @BeforeMethod(alwaysRun = true)
    public void createCaseData() {
        System.out.println("before each test method");
    }

    @Test
    public void createsOrder() {
        System.out.println("test body");
    }

    @AfterMethod(alwaysRun = true)
    public void deleteCaseData() {
        System.out.println("cleanup each method");
    }
}

Choose scope by ownership. A browser per method gives strong isolation. An immutable API client can be class or suite scoped. Mutable order data should be invocation scoped. Configuration code should fail fast with useful context and cleanup should tolerate partial setup.

3. Tests, Assertions, Groups, Parameters, and Dependencies

@Test supports attributes including groups, dependsOnMethods, dependsOnGroups, enabled, priority, timeOut, invocationCount, successPercentage, dataProvider, and expectedExceptions. Use them only when the execution contract requires them. Priority creates ordering but not business independence. A regression suite built from many priorities can become one fragile workflow.

TestNG offers hard and soft assertions. Assert fails immediately when an assertion fails. SoftAssert records failures until assertAll() is called. Soft assertions are useful when several independent checks on the same loaded state should be reported together. Forgetting assertAll() creates a false pass, and continuing after a critical precondition can produce misleading secondary failures.

Groups are labels used for selection and configuration. Examples include smoke, regression, api, and capabilities such as payments. Avoid a separate group for every pipeline. Build jobs can compose stable semantic groups through suite XML. @BeforeGroups and @AfterGroups exist, but complex group fixtures can hide dependencies.

@Parameters reads values from suite XML and is suitable for a small execution setting such as browser or region. @Optional can supply a default. A DataProvider is better for multiple scenario rows and complex objects. Keep secrets outside suite XML stored in source control.

Dependencies model a genuine prerequisite. If the prerequisite fails, dependent tests are skipped by default. Most product tests should create prerequisites through APIs or fixtures rather than depend on another test's side effects. Use a dependency for a deliberately ordered workflow, not to avoid independent setup.

4. DataProvider, Factory, and Parameterized Test Questions

A @DataProvider supplies arguments to a test method. It can return Object[][], Iterator<Object[]>, arrays of custom objects, and other supported forms. The provider name can be explicit, and dataProviderClass can reference a separate class whose provider method is static when TestNG cannot instantiate it as the test class.

package example.data;

import static org.testng.Assert.assertEquals;
import java.math.BigDecimal;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DiscountTest {
    record Case(String name, BigDecimal subtotal,
                BigDecimal rate, BigDecimal expected) { }

    @DataProvider(name = "discountCases")
    public Object[][] discountCases() {
        return new Object[][] {
            { new Case("no discount", new BigDecimal("100.00"),
                    new BigDecimal("0.00"), new BigDecimal("100.00")) },
            { new Case("ten percent", new BigDecimal("80.00"),
                    new BigDecimal("0.10"), new BigDecimal("72.00")) }
        };
    }

    @Test(dataProvider = "discountCases")
    public void calculatesDiscount(Case testCase) {
        BigDecimal actual = testCase.subtotal()
                .multiply(BigDecimal.ONE.subtract(testCase.rate()));
        assertEquals(actual, testCase.expected(), testCase.name());
    }
}

This example uses BigDecimal for exact decimal expectations. In an interview, explain why a named record is clearer than five unlabelled arguments. Also mention edge cases, such as negative values, excessive rates, rounding policy, and null handling, according to the product contract.

parallel = true on a DataProvider permits rows to run concurrently. It does not copy mutable objects safely. Return immutable values, create unique external data per row, and keep report files separate. If the provider reads a large source, an iterator can avoid constructing every row at once, but external input must remain deterministic and validated.

@Factory creates test class instances, often when constructor-level state varies across instances. Use DataProvider when one method consumes rows. Use Factory when instance identity, configuration methods, or several test methods should share a constructed scenario object.

5. Parallel Execution, Thread Safety, and WebDriver

TestNG supports parallel modes such as methods, classes, tests, and instances. Suite thread-count limits relevant worker concurrency. Parallel DataProviders have related configuration. A senior answer does not stop at the XML attribute. It explains isolation and capacity.

Parallel unit Useful when Main risk
Methods Independent methods own all state Mutable class fields race
Classes Methods within a class share deliberate state One slow class limits distribution
Tests <test> blocks represent browser or platform partitions Hidden suite resources overlap
Instances Factory instances model isolated scenarios Static state still leaks
DataProvider rows One scenario scales across datasets Records and artifacts collide

WebDriver sessions should not be shared. A common Java design uses one method-scoped session per invocation and a ThreadLocal<WebDriver> lookup for TestNG thread affinity. ThreadLocal does not make a driver thread-safe. It gives each thread a different reference, and remove() is required after quit() because workers are reused. The ThreadLocal WebDriver guide covers the full lifecycle.

Parallel safety includes accounts, database rows, downloads, temporary directories, ports, screenshots, listeners, and report aggregation. ArrayList and plain integer listener fields are not safe for concurrent callbacks. Immutable events, concurrent collections, atomic counters, and invocation-specific paths are safer.

Do not maximize thread count blindly. Grid slots, CI CPU, application rate limits, database locks, and test data capacity set a practical limit. Begin with a small stable count and observe queue time, active sessions, failure signatures, and cleanup.

6. Listeners, Retry Analyzers, and Reports

TestNG listener interfaces expose different lifecycle scopes. ITestListener observes test results. IInvokedMethodListener surrounds test and configuration invocations. IConfigurationListener observes setup and teardown results. ISuiteListener surrounds suites. IExecutionListener surrounds the complete TestNG execution. IReporter generates output after suites finish.

Listeners are appropriate for logging, metrics, screenshots, result metadata, and custom reporting. They should not click product controls or replace business assertions. Register them with @Listeners, suite XML, build configuration, service loading, or programmatically. Avoid duplicate registration. IAnnotationTransformer must be registered early, so do not rely on @Listeners for it.

IRetryAnalyzer.retry(ITestResult) returns true when TestNG should repeat a failed invocation. A strong answer emphasizes a small bounded retry for explicitly classified transient infrastructure failures. Assertions, invalid locators, null pointer exceptions, and deterministic configuration defects should not be retried by default. Preserve the first failure and label a pass-after-retry as flaky.

package example.retry;

import java.util.concurrent.atomic.AtomicInteger;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public final class OneRetryForTransientFailure
        implements IRetryAnalyzer {
    private final AtomicInteger retries = new AtomicInteger();

    @Override
    public boolean retry(ITestResult result) {
        boolean eligible = result.getThrowable()
                instanceof TransientEnvironmentException;
        return eligible && retries.getAndIncrement() < 1;
    }

    public static final class TransientEnvironmentException
            extends RuntimeException {
        public TransientEnvironmentException(String message) {
            super(message);
        }
    }
}

Counters need logical invocation isolation for DataProvider rows. The tiny example explains the interface, while a production policy must key attempts safely and report each attempt.

7. Suite XML, Maven, and CI Execution

Suite XML composes tests, parameters, listeners, groups, packages, classes, methods, parallel mode, and thread count. It is useful when the execution matrix is part of test configuration. Keep suite files reviewed and avoid duplicating many nearly identical versions.

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Release regression" parallel="tests" thread-count="2">
  <listeners>
    <listener class-name="example.reporting.ResultListener"/>
  </listeners>
  <test name="Chrome smoke">
    <parameter name="browser" value="chrome"/>
    <groups>
      <run><include name="smoke"/></run>
    </groups>
    <packages>
      <package name="example.tests"/>
    </packages>
  </test>
  <test name="Firefox smoke">
    <parameter name="browser" value="firefox"/>
    <groups>
      <run><include name="smoke"/></run>
    </groups>
    <packages>
      <package name="example.tests"/>
    </packages>
  </test>
</suite>

Maven Surefire commonly runs TestNG tests in the test phase and can select suite XML files. Maven Failsafe is commonly configured for integration-test and verify, which is useful when browser tests need post-test cleanup before the build outcome is finalized. Explain your repository's actual plugin setup rather than claiming one mandatory arrangement.

CI should install the selected JDK, resolve locked dependencies, inject nonsecret environment configuration and protected secrets, execute the build command, preserve the process exit code, and upload TestNG XML plus artifacts. A report portal showing red while Maven exits zero is unsafe. Conversely, a failed optional report upload should not erase local test evidence.

TestNG generates testng-failed.xml for rerunning failed methods with required dependencies. That separate rerun differs from an in-run retry analyzer and from rerunning the complete CI job. State which scope you choose and why.

8. Framework Design and a Practical Coding Exercise

A maintainable framework usually separates tests, page or API clients, immutable scenario data, configuration, lifecycle, assertions, and reporting. A large BaseTest with dozens of protected fields creates hidden coupling. Use a small base only for unavoidable runner lifecycle, then compose services explicitly.

Consider this interview task: read browser names from a DataProvider and prove each row invokes a factory without opening a real browser. Model the factory behind an interface so the test is deterministic.

package example.design;

import static org.testng.Assert.assertEquals;
import java.util.Locale;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class BrowserSelectionTest {
    interface BrowserFactory { String create(String name); }

    static final class ValidatingFactory implements BrowserFactory {
        @Override public String create(String name) {
            return switch (name.toLowerCase(Locale.ROOT)) {
                case "chrome", "firefox" -> name.toLowerCase(Locale.ROOT);
                default -> throw new IllegalArgumentException(
                        "Unsupported browser: " + name);
            };
        }
    }

    @DataProvider
    public Object[][] browsers() {
        return new Object[][] { { "chrome" }, { "FIREFOX" } };
    }

    @Test(dataProvider = "browsers")
    public void createsSupportedBrowser(String requested) {
        String actual = new ValidatingFactory().create(requested);
        assertEquals(actual, requested.toLowerCase(Locale.ROOT));
    }
}

Discuss additional cases: null, blank, whitespace, unsupported value, and locale-safe normalization. Then explain where a live Selenium integration test belongs. The unit test validates selection cheaply, while a small environment matrix proves the real constructors and Grid capabilities.

Interviewers value boundaries. Configuration validates strings. A factory creates sessions. Lifecycle owns cleanup. Pages model interactions. Tests state behavior. Listeners observe outcomes.

9. Debugging Failed, Skipped, and Flaky TestNG Runs

Begin with the first causal failure, not the largest number of skipped tests. A failed @BeforeSuite or @BeforeClass can skip many tests. Inspect configuration results, full throwable chains, suite XML, selected groups, environment, parameters, worker threads, and artifacts.

A skipped test may result from a failed dependency, failed configuration, explicit SkipException, group selection, or disabled configuration. A test absent from the report may not have been discovered because of naming rules, build includes, package selection, or annotation issues. Distinguish not discovered from skipped.

For flakiness, preserve the first attempt and classify product, test, data, and environment causes. Replace sleeps with observable conditions, isolate records, fix non-thread-safe state, and verify teardown. A retry is evidence, not root-cause analysis. The flaky test debugging workflow gives a systematic sequence.

When a test passes alone but fails in a suite, suspect shared state, order dependency, data collision, resource saturation, or configuration differences. Randomize or reorder a small group, reduce concurrency, log stable case IDs, and compare session and record ownership. Do not merely increase all timeouts.

When local and CI outcomes differ, compare JDK, browser, dependencies, timezone, locale, filesystem, headless mode, CPU, network routes, secrets, and selected suite. Capture these as run metadata so the next failure has evidence.

10. TestNG Interview Questions and Answers for Scenario Rounds

Scenario questions reveal judgment. For a suite that takes two hours, do not immediately recommend more threads. Measure duration by layer and test, move UI prerequisites to APIs, remove duplicate coverage, shard independent groups, and verify environment capacity. Parallelism comes after isolation.

For a flaky checkout case, preserve screenshot, DOM, request correlation ID, browser logs, test data ID, and timing. Determine whether the product returned the wrong state, the test observed too early, records collided, or a dependency failed. Add a narrow fix and repeat under the original failure condition.

For a screenshot requirement, use a listener or teardown hook while the driver is alive. Generate unique paths by case and attempt. Catch artifact failure separately and never convert the assertion result. For configuration failure, use IConfigurationListener or invoked-method hooks because the test body may never fail directly.

For multi-browser execution, prefer a validated browser parameter and stateless factory. Suite <test> blocks or a CI matrix can partition browsers. Each invocation receives a distinct driver and artifact directory. Report browser, version, platform, and session ID without leaking Grid credentials.

For dependent tests, ask whether the relationship is business workflow or test convenience. Create prerequisites through APIs for independent regression cases. Keep explicit dependencies only when the ordered journey is the behavior being tested, and accept that downstream skips are expected evidence.

Interview Questions and Answers

Q: What is TestNG?

TestNG is a Java testing framework that provides annotations, scoped configuration, assertions, DataProviders, groups, dependencies, factories, listeners, parallel execution, suite XML, and reports. I use its features to express test execution and lifecycle, while keeping product behavior in test and domain code.

Q: What is the difference between @BeforeTest and @BeforeMethod?

@BeforeTest runs before the tests inside a <test> element in suite XML. @BeforeMethod runs before each eligible test method. I choose based on resource ownership rather than annotation name.

Q: What is alwaysRun used for?

It helps configuration methods run despite group restrictions or earlier failures according to TestNG lifecycle rules. I commonly use it on teardown so cleanup is attempted after a failed test. It cannot guarantee execution after an abrupt process termination.

Q: Hard Assert or SoftAssert?

A hard assertion stops the current test immediately. SoftAssert records failures until assertAll(), which is useful for independent checks on one state. I do not continue with soft checks after a critical prerequisite fails.

Q: DataProvider or @Parameters?

I use @Parameters for a few suite-level execution settings and DataProvider for multiple test rows or typed scenario objects. Secrets do not belong in committed XML. Parallel DataProviders require immutable input and isolated external data.

Q: DataProvider or Factory?

A DataProvider feeds arguments to a method. A Factory creates test class instances, which is useful when constructor state applies across configuration and several methods. I choose the smallest model that represents the scenario.

Q: How does TestNG support parallel testing?

Suite XML can parallelize methods, classes, tests, or instances, and DataProviders can run rows in parallel. The hard work is isolating drivers, data, files, accounts, and listener state and matching worker count to environment capacity.

Q: What is a TestNG listener?

It is an implementation of a TestNG callback interface for lifecycle observation or extension. I use listeners for logs, screenshots, metrics, and reports, not for business steps.

Q: How do you retry a failed test?

Implement IRetryAnalyzer and return true only within a strict bound for an eligible failure. Preserve every attempt and report pass-after-retry as flaky. Deterministic assertions and test defects should not be retried by default.

Q: Why was my test skipped?

I inspect failed dependencies, configuration results, thrown SkipException, group selection, and enablement. I distinguish a discovered skip from a test that build or suite selection never discovered.

Q: How do you run only smoke tests?

Annotate stable semantic groups and include smoke through suite XML or the build's TestNG group configuration. I verify exclusions and avoid encoding pipeline names into test logic.

Q: What is testng-failed.xml?

It is a generated suite containing failed methods and required dependencies for a separate rerun. It differs from an IRetryAnalyzer, which repeats an invocation during the same run, and from rerunning the full CI job.

Q: Can tests depend on other tests?

TestNG supports method and group dependencies, but most regression cases should create their own prerequisites. I use dependencies only for an intentionally ordered workflow where downstream skips are meaningful.

Q: How do you debug a test that fails only in parallel?

I correlate test, thread, session, data, and artifact IDs, then reduce concurrency and look for shared mutable state or capacity limits. I test drivers, accounts, records, files, and listeners separately. A synchronized shared driver is not proper isolation.

Q: How do you integrate TestNG with CI?

The build tool runs the selected suites or groups and preserves a nonzero result for real failures. CI injects protected configuration, publishes TestNG XML and artifacts, and records runtime metadata. Optional report publication cannot erase local evidence.

Common Mistakes

  • Memorizing annotation order without understanding resource scope.
  • Saying @BeforeTest runs before every Java test method.
  • Using priority to create a large order-dependent regression workflow.
  • Forgetting SoftAssert.assertAll() and reporting false passes.
  • Sharing WebDriver, accounts, records, or filenames in parallel tests.
  • Treating ThreadLocal as proof that every resource is thread-safe.
  • Retrying all failures and reporting only the final pass.
  • Using listeners for browser workflow or changing raw result statuses.
  • Storing secrets in testng.xml, source files, logs, or DataProvider output.
  • Ignoring configuration failures when many tests are skipped.
  • Maximizing thread count without checking Grid and application capacity.
  • Claiming TestNG is universally better than JUnit instead of explaining project fit.

Conclusion

Testng interview questions and answers test your mental model of reliable execution. Learn configuration scope, test selection, data-driven design, parallel isolation, listener boundaries, retries, reporting, and CI as one connected system. Then support definitions with one small runnable example and one real debugging story.

Practice explaining why a test is independent, how its resources are cleaned, and what evidence remains after failure. Those answers show the judgment an automation team needs far better than a long list of annotation names.

Interview Questions and Answers

What is TestNG?

TestNG is a Java test framework with annotations, scoped configuration, assertions, groups, DataProviders, dependencies, factories, listeners, suite XML, and parallel execution. I use it to define test lifecycle and execution while keeping product behavior in test and domain code.

Explain the TestNG configuration lifecycle.

The broad order is before suite, test, class, and method, followed by the test method and matching after configurations in reverse scope. `@BeforeTest` means before a suite XML `<test>`, not before one Java test. I select scope by the lifetime of the resource.

What does alwaysRun mean?

It influences whether a configuration method runs despite group selection or preceding failures under TestNG's rules. It is especially useful for cleanup methods. It cannot guarantee cleanup after a killed process or machine loss.

Compare Assert and SoftAssert.

A hard assertion stops the current test at the failed check. `SoftAssert` accumulates failures until `assertAll()`. I use soft checks only when later checks remain meaningful and never omit `assertAll()`.

Compare DataProvider and Parameters.

Parameters are convenient for small suite-level values from XML, such as browser or region. DataProviders model several rows and can pass typed objects. Secrets stay in protected configuration, and parallel rows receive isolated data.

When would you use a TestNG Factory?

A Factory creates test class instances, so constructor state can apply to configuration and multiple methods. A DataProvider is simpler when only one test method needs rows. I avoid Factory when it adds instance lifecycle without a real need.

How do you execute TestNG methods in parallel safely?

I choose the intended parallel unit and a capacity-aware thread count. Each active invocation owns its driver, records, account, output paths, and safe report state. I correlate test, thread, session, and data IDs to verify isolation.

What is ITestListener used for?

It observes test result and context events, making it useful for status logging, failure evidence, metadata, and summaries. Configuration failures may need `IConfigurationListener`. Business actions and assertions do not belong in listeners.

How does IRetryAnalyzer work?

After an associated test failure, TestNG calls `retry(ITestResult)`. Returning true schedules another attempt. I use a bounded counter, narrow transient classification, fresh attempt state, and reports that preserve the original failure.

What causes a TestNG test to be skipped?

A failed dependency or configuration, explicit `SkipException`, or selection rules can produce a skip. I inspect configuration and dependency results before debugging the skipped body. I also verify the test was actually discovered.

What is testng-failed.xml?

TestNG generates it to support a separate rerun of failed methods and required dependencies. It is broader and later than an in-run retry analyzer. I retain original run evidence when using it.

How would you run smoke and regression groups?

I attach semantic group names and include or exclude them through suite XML or build configuration. Tests do not inspect pipeline names. Group-specific fixtures remain small because complex hidden selection makes failures harder to understand.

Should TestNG tests depend on each other?

The framework supports dependencies, but independent regression tests are safer. I create prerequisites through APIs or fixtures. I reserve dependencies for an intentional ordered workflow where a downstream skip is the correct signal.

How do you diagnose a parallel-only failure?

I capture stable test, thread, session, record, and account identifiers and compare overlapping executions. Then I reduce concurrency and audit shared mutable fields, files, listeners, and environment limits. I fix ownership rather than adding blanket synchronization.

How do you integrate TestNG reports with CI?

The build publishes TestNG XML and invocation artifacts while preserving the process exit code. CI records environment metadata and keeps report upload separate enough that an external reporting outage cannot erase local evidence. Retries remain visible as attempts.

Frequently Asked Questions

What TestNG topics are asked in automation interviews?

Common topics include annotations, lifecycle, assertions, groups, parameters, DataProviders, factories, dependencies, parallel execution, listeners, retry analyzers, suite XML, Maven, reports, and failure debugging.

What is the correct TestNG annotation order?

The common scope order is before suite, test, class, method, then the test, followed by after method, class, test, and suite. Inheritance, groups, failures, and multiple methods can affect the complete event sequence.

What is the difference between BeforeTest and BeforeMethod in TestNG?

`@BeforeTest` applies to a `<test>` block from suite XML. `@BeforeMethod` applies before each eligible `@Test` method, making it common for invocation-specific setup.

How do DataProviders work in TestNG?

A `@DataProvider` returns rows of arguments that TestNG supplies to a named test method. Rows can run sequentially or in parallel, but typed immutable data and external resource isolation are essential.

How do I run TestNG tests in parallel?

Configure a parallel unit such as methods, classes, tests, or instances and a thread count in suite XML, or use a parallel DataProvider. First isolate browsers, records, accounts, files, and listener state.

What is IRetryAnalyzer in TestNG?

It is an interface whose `retry(ITestResult)` method decides whether a failed invocation should repeat. Use a small limit and narrow transient eligibility, then preserve all attempts in reporting.

Why are TestNG tests skipped?

Common causes are failed dependencies, failed configuration methods, `SkipException`, group filters, or explicit enablement. A test excluded from discovery is absent rather than skipped, so inspect build and suite selection too.

Related Guides