TestNG interview questions — Medium

246 medium-level TestNG questions from our Automation Testing bank, each with the correct answer and an explanation of why it is correct.

What this covers

TestNG appears throughout Automation Testing interviews. At medium level, interviewers are typically checking that you have used it in practice: what you configured, what broke, and how you knew it worked. Work through these, then explain your answer out loud; the second part is what interviews actually test.

20 example questions

  1. 1. "Injects values defined in testng.xml into a test method" — in TestNG, this describes which of the following?

    • A. Thread-count.
    • B. @Parameters.correct
    • C. IRetryAnalyzer.
    • D. @Test.

    Why: @Parameters: Injects values defined in testng.xml into a test method.

  2. 2. "testng.xml attribute controlling parallel thread pool size" — in TestNG, this describes which of the following?

    • A. @AfterSuite.
    • B. TimeOut attribute.
    • C. Thread-count.correct
    • D. @Ignore / enabled=false.

    Why: thread-count: testng.xml attribute controlling parallel thread pool size.

  3. 3. "Interface used to automatically retry failed tests" — in TestNG, this describes which of the following?

    • A. Thread-count.
    • B. @AfterSuite.
    • C. IRetryAnalyzer.correct
    • D. @Test.

    Why: IRetryAnalyzer: Interface used to automatically retry failed tests.

  4. 4. "Collects assertion failures and reports them at assertAll()" — in TestNG, this describes which of the following?

    • A. Thread-count.
    • B. @AfterSuite.
    • C. SoftAssert.correct
    • D. TimeOut attribute.

    Why: SoftAssert: Collects assertion failures and reports them at assertAll().

  5. 5. "Marks a method as a TestNG test" — in TestNG, this describes which of the following?

    • A. AssertEquals.
    • B. @Test.correct
    • C. Thread-count.
    • D. IRetryAnalyzer.

    Why: @Test: Marks a method as a TestNG test.

  6. 6. Identify the accurate statement about TestNG:

    • A. Testng.xml files cannot pass parameters to test methods.
    • B. @BeforeClass runs before every individual test method.
    • C. Groups allow including or excluding categorized tests at runtime.correct
    • D. DependsOnMethods causes the dependent test to run even if the prerequisite fails, by default.

    Why: @Test(groups={...}) plus testng.xml include/exclude filters execution.

  7. 7. Which statement correctly describes TestNG?

    • A. DependsOnMethods causes the dependent test to run even if the prerequisite fails, by default.
    • B. Groups allow including or excluding categorized tests at runtime.correct
    • C. Testng.xml files cannot pass parameters to test methods.
    • D. A @DataProvider may only return a single row of data.

    Why: @Test(groups={...}) plus testng.xml include/exclude filters execution.

  8. 8. "Runs once after all tests in the suite finish" — in TestNG, this describes which of the following?

    • A. @AfterSuite.correct
    • B. Thread-count.
    • C. IRetryAnalyzer.
    • D. @Parameters.

    Why: @AfterSuite: Runs once after all tests in the suite finish.

  9. 9. In TestNG, when does a method annotated @BeforeMethod run?

    • A. Once before all tests in the class.
    • B. Before each @Test method.correct
    • C. Only before the first @Test.
    • D. After every @Test.

    Why: @BeforeMethod runs before every @Test method; @BeforeClass runs once before any test method in the class.

  10. 10. "Skips a test from execution" — in TestNG, this describes which of the following?

    • A. @Ignore / enabled=false.correct
    • B. @AfterSuite.
    • C. TimeOut attribute.
    • D. @Parameters.

    Why: @Ignore / enabled=false: Skips a test from execution.

  11. 11. Which of the following statements about TestNG is TRUE?

    • A. TestNG cannot run tests in parallel without a third-party plugin.
    • B. @BeforeClass runs before every individual test method.
    • C. DependsOnMethods causes the dependent test to run even if the prerequisite fails, by default.
    • D. Testng.xml defines suites, tests, groups, parameters, and parallel execution settings.correct

    Why: The XML file orchestrates what runs and how.

  12. 12. Which TestNG concept matches this description: "Fails a test if it exceeds the given milliseconds"?

    • A. @Ignore / enabled=false.
    • B. TimeOut attribute.correct
    • C. IRetryAnalyzer.
    • D. Thread-count.

    Why: timeOut attribute: Fails a test if it exceeds the given milliseconds.

  13. 13. Which TestNG concept matches this description: "testng.xml attribute controlling parallel thread pool size"?

    • A. @Parameters.
    • B. @AfterSuite.
    • C. Thread-count.correct
    • D. IRetryAnalyzer.

    Why: thread-count: testng.xml attribute controlling parallel thread pool size.

  14. 14. Which TestNG concept matches this description: "Injects values defined in testng.xml into a test method"?

    • A. AssertEquals.
    • B. Thread-count.
    • C. SoftAssert.
    • D. @Parameters.correct

    Why: @Parameters: Injects values defined in testng.xml into a test method.

  15. 15. In TestNG, which of the following is described as: "Fails a test if it exceeds the given milliseconds"?

    • A. TimeOut attribute.correct
    • B. Thread-count.
    • C. @AfterSuite.
    • D. @Ignore / enabled=false.

    Why: timeOut attribute: Fails a test if it exceeds the given milliseconds.

  16. 16. In TestNG, which of the following is described as: "Interface used to automatically retry failed tests"?

    • A. IRetryAnalyzer.correct
    • B. Thread-count.
    • C. @AfterSuite.
    • D. AssertEquals.

    Why: IRetryAnalyzer: Interface used to automatically retry failed tests.

  17. 17. In TestNG, which of the following is described as: "testng.xml attribute controlling parallel thread pool size"?

    • A. Thread-count.correct
    • B. SoftAssert.
    • C. @AfterSuite.
    • D. TimeOut attribute.

    Why: thread-count: testng.xml attribute controlling parallel thread pool size.

  18. 18. Which TestNG concept matches this description: "Soft/hard assertion comparing expected and actual values"?

    • A. @AfterSuite.
    • B. @Test.
    • C. Thread-count.
    • D. AssertEquals.correct

    Why: assertEquals: Soft/hard assertion comparing expected and actual values.

  19. 19. Which TestNG concept matches this description: "Interface used to automatically retry failed tests"?

    • A. @Parameters.
    • B. @Test.
    • C. @AfterSuite.
    • D. IRetryAnalyzer.correct

    Why: IRetryAnalyzer: Interface used to automatically retry failed tests.

  20. 20. In TestNG, which of the following is described as: "Injects values defined in testng.xml into a test method"?

    • A. @Parameters.correct
    • B. IRetryAnalyzer.
    • C. @AfterSuite.
    • D. TimeOut attribute.

    Why: @Parameters: Injects values defined in testng.xml into a test method.

Related Automation Testing topics