TestNG interview questions — Hard
126 hard-level TestNG questions from our Automation Testing bank, each with the correct answer and an explanation of why it is correct.
This topic slice is available to practise but is not yet part of our indexed set.
What this covers
TestNG appears throughout Automation Testing interviews. At hard level, interviewers are typically checking depth under pressure — edge cases, failure modes, performance characteristics, and the trade-offs you accepted. Work through these, then explain your answer out loud; the second part is what interviews actually test.
5 example questions
1. Regarding TestNG, which of the following is a false statement?
- A. A @DataProvider may only return a single row of data.correct
- B. ITestListener lets you hook into events like onTestFailure for custom reporting or screenshots.
- C. TestNG supports parallel execution at methods, classes, tests, or instances level via the parallel attribute.
- D. The @DataProvider annotation supplies multiple data sets to a test method for data-driven testing.
Why: The selected statement is false. The other options are accurate statements about TestNG.
2. In a test-strategy meeting, the question comes up: When does a TestNG @BeforeMethod run?
- A. Once before all tests.
- B. Before each @Test method.correct
- C. Before the first @Test only.
- D. After every @Test.
Why: @BeforeMethod runs before every @Test; @BeforeClass runs once per class.
3. Identify the INCORRECT statement about TestNG:
- A. Testng.xml defines suites, tests, groups, parameters, and parallel execution settings.
- B. TestNG has no listener mechanism for reacting to test failures.correct
- C. The @DataProvider annotation supplies multiple data sets to a test method for data-driven testing.
- D. TestNG supports parallel execution at methods, classes, tests, or instances level via the parallel attribute.
Why: The selected statement is false. The other options are accurate statements about TestNG.
4. Which statement about TestNG is NOT correct?
- A. Groups allow including or excluding categorized tests at runtime.
- B. DependsOnMethods makes one test run only after another test passes.
- C. TestNG has no listener mechanism for reacting to test failures.correct
- D. The priority attribute orders test method execution, lower values first.
Why: The selected statement is false. The other options are accurate statements about TestNG.
5. Which of the following statements about TestNG is FALSE?
- A. Groups allow including or excluding categorized tests at runtime.
- B. A @DataProvider may only return a single row of data.correct
- C. ExpectedExceptions asserts that a test throws a specific exception.
- D. DependsOnMethods makes one test run only after another test passes.
Why: The selected statement is false. The other options are accurate statements about TestNG.