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 pageshowhide
explore
- @Test Settings5 questions
- Configuration Hook Order5 questions
- Groups & Dependencies5 questions
- @DataProvider & @Factory5 questions
- Suite File & Thread Modes5 questions
- Listeners & Retry5 questions
- Hard and Soft Asserts5 questions
- Choosing a JVM Runner5 questions
questions
page 2 of 2After 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?
basics
~20 stestng-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.
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?
basics
~20 sexpectedExceptions 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.
When porting tests between TestNG and JUnit Jupiter, which behaviours change silently even though every test compiles and the build stays green?
basics
~20 sInstance 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.
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?
basics
~20 sAllow 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.
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?
basics
~20 sA 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.
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?
basics
~10 sThere 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.
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?
basics
~20 sNot 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.
What does TestNG's Assert.assertEqualsNoOrder check, and how does it treat duplicate elements and nested arrays?
basics
~10 sTestNG'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.
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?
basics
~20 sA 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.
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?
basics
~20 sTestNG 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.
showing 31–40 of 40