skip to content

TestNG

The other JVM runner: groups, data providers, declared dependencies between tests, and an XML suite file that configures parallelism. Asked so you can justify it against JUnit for a given suite.

on this pageshow

explore

questions

page 2 of 2

After a failing TestNG cross-browser run, what does testng-failed.xml contain, and why can a green rerun of it still hide the failure's real cause?

level: seniorimportance: should knowfreq 45%

basics

~20 s

testng-failed.xml is a generated suite holding the failed and skipped test methods, the methods they depend on and their configuration methods, with the original attributes and parameters. A green rerun runs far fewer tests, so interference and load disappear.

open as a page

A TestNG validation test with `@Test(expectedExceptions = IllegalArgumentException.class)` stayed green after the validation it covers was deleted; how can that happen, and how do you harden it?

level: seniorimportance: should knowfreq 40%

basics

~20 s

expectedExceptions passes when any statement in the method throws the declared type or a subclass, so a NumberFormatException from parsing test data satisfies IllegalArgumentException. Harden it with a full-match message regex and by asserting on the one call that must throw.

open as a page

When porting tests between TestNG and JUnit Jupiter, which behaviours change silently even though every test compiles and the build stays green?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Instance lifecycle (TestNG shares one instance per class, Jupiter makes one per method), dependency skips, suite-file group excludes and parallel settings, assert argument order, and the scope of exception expectations all change without a compile error.

open as a page

As the lead of a large TestNG suite, would you allow dependsOnMethods at all, and what rule would you set for when it is acceptable?

level: principalimportance: should knowfreq 38%

basics

~20 s

Allow dependsOnMethods only as a reviewed exception: for steps of one workflow in one class, where a later step is meaningless after an earlier failure. Setup goes in configuration methods, and every other test must run and pass on its own.

open as a page

As the lead of a TestNG UI suite, what retry policy would you set for IRetryAnalyzer, and how would you stop retries from hiding flaky tests?

level: principalimportance: should knowfreq 35%

basics

~20 s

A sound TestNG retry policy is opt-in per @Test rather than a blanket transformer, capped at about one retry, limited to infrastructure exceptions, and makes every wasRetried() attempt visible, with evidence and an owner, so flakes get fixed.

open as a page

As the lead of a large TestNG Selenium suite, which parallel mode and thread-count would you make the team default in testng.xml, and how would you defend it?

level: principalimportance: should knowfreq 38%

basics

~10 s

There is no universal answer, but a defensible default for a TestNG Selenium suite is parallel="classes", or parallel="tests" for a per-browser matrix, with thread-count sized to available browser capacity and measured, not guessed.

open as a page

Your organisation runs a large TestNG Selenium suite beside backend services tested with JUnit Jupiter. Would you standardise on one runner, and how would you decide?

level: principalimportance: should knowfreq 30%

basics

~20 s

Not by default. Inventory which TestNG-only features the Selenium suite relies on, price the redesign, and usually standardise on JUnit Jupiter for new code while keeping the working TestNG suite until a real trigger justifies migrating it.

open as a page

What does TestNG's Assert.assertEqualsNoOrder check, and how does it treat duplicate elements and nested arrays?

level: middleimportance: nice to knowfreq 28%

basics

~10 s

TestNG's Assert.assertEqualsNoOrder passes when two arrays, collections or iterators hold the same elements in any order. Sizes must match and each duplicate must appear equally often; nested arrays are compared by reference, not deeply.

open as a page

A TestNG class carries a class-level `@Test(enabled = false)`, yet its methods with their own `@Test` still run; why, and what reliably disables the whole class?

level: seniorimportance: nice to knowfreq 30%

basics

~20 s

A method's own @Test replaces the class-level one, and enabled is not inherited, so those methods default to enabled. Class-level enabled = false only disables unannotated public methods; @Ignore on the class disables every test method in it.

open as a page

After upgrading TestNG from 7.9 to 7.12, a suite that ran JUnit 4 classes through TestNG reports far fewer tests. What happened, and how do you fix it?

level: seniorimportance: nice to knowfreq 28%

basics

~20 s

TestNG 7.10.0 removed its ability to run JUnit 3 and 4 tests, deprecated since 7.7.0. junit="true" now only prints a removal message, so those classes quietly stop running. Run them on the JUnit Platform, or migrate them.

open as a page

showing 31–40 of 40