TestNG Interview Cheat Sheet

Free · 4 pages · PDF

Revise TestNG for Selenium interviews in 15–20 minutes: annotations order, DataProvider, groups, parallel runs, listeners and 20 interview Q&A.

Topics: TestNG, Java, Selenium, Interview

About this cheat sheet

The TestNG Interview Cheat Sheet lets you revise the whole TestNG ecosystem in 15–20 minutes before a Java Selenium automation interview. Four dense A4 pages take you from "what is TestNG?" to the framework topics that separate experienced SDETs from beginners.

It's written in plain English for freshers, automation engineers with 1–5 years of experience and senior engineers brushing up before an interview. Every concept comes with a short, practical Selenium example instead of textbook definitions: where to open and close the browser, how to run only smoke tests, how to make parallel tests thread-safe and how to capture a screenshot when a test fails.

The examples target TestNG 7.12, Java 17 and Selenium 4 and were checked against the official TestNG documentation. The sheet also flags the traps interviewers love, such as @BeforeTest running once per <test> tag rather than per test method, and setup methods silently skipped when you run by groups.

What’s inside

  • What TestNG is, why Selenium teams use it, and the key differences between TestNG and JUnit 5
  • TestNG annotations and their exact execution order, from @BeforeSuite to @AfterSuite
  • Where to launch and quit the browser in a Selenium BaseTest, and why alwaysRun = true matters
  • Important @Test attributes: priority, enabled, invocationCount, timeOut, expectedExceptions and more
  • Hard assertions vs SoftAssert, and the assertAll() mistake that hides failures
  • Data-driven testing with @DataProvider and @Parameters, and when to use each
  • Test dependencies, groups (smoke, sanity, regression) and running selected groups from testng.xml
  • TestNG parallel execution (methods, classes, tests, instances) with a thread-safe ThreadLocal WebDriver
  • TestNG listeners: ITestListener, ISuiteListener, IRetryAnalyzer, IAnnotationTransformer, plus a screenshot-on-failure example
  • How to retry failed tests responsibly, and a complete testng.xml with suites, tests, groups, parameters and parallel settings
  • @Factory, @Ignore and other concepts interviewers ask about
  • Top 20 TestNG interview questions, 5 real-world scenarios and a last-minute revision table

Get your free copy on this page: download instantly, and we email you a copy of the link.