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. 1. In a CI/CD pipeline review, consider this: 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.

  2. 2. Regarding TestNG, which of the following is a false statement?

    • A. @BeforeMethod runs before each test method, while @BeforeClass runs once per class.
    • B. TestNG has no listener mechanism for reacting to test failures.correct
    • C. DependsOnMethods makes one test run only after another test passes.
    • 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.

  3. 3. Which of the following statements about TestNG is FALSE?

    • A. TestNG supports parallel execution at methods, classes, tests, or instances level via the parallel attribute.
    • B. DependsOnMethods causes the dependent test to run even if the prerequisite fails, by default.correct
    • C. ExpectedExceptions asserts that a test throws a specific exception.
    • D. Testng.xml defines suites, tests, groups, parameters, and parallel execution settings.

    Why: The selected statement is false. The other options are accurate statements about TestNG.

  4. 4. Which statement about TestNG is NOT correct?

    • A. ExpectedExceptions asserts that a test throws a specific exception.
    • B. Testng.xml defines suites, tests, groups, parameters, and parallel execution settings.
    • C. DependsOnMethods makes one test run only after another test passes.
    • D. Testng.xml files cannot pass parameters to test methods.correct

    Why: The selected statement is false. The other options are accurate statements about TestNG.

  5. 5. Identify the INCORRECT statement about TestNG:

    • A. InvocationCount runs the same test method multiple times.
    • B. @BeforeClass runs before every individual test method.correct
    • C. DependsOnMethods makes one test run only after another test passes.
    • D. ITestListener lets you hook into events like onTestFailure for custom reporting or screenshots.

    Why: The selected statement is false. The other options are accurate statements about TestNG.

Related Automation Testing topics