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. "Interface used to automatically retry failed tests" — in TestNG, this describes which of the following?
- A. @Parameters.
- B. @AfterSuite.
- C. IRetryAnalyzer.correct
- D. TimeOut attribute.
Why: IRetryAnalyzer: Interface used to automatically retry failed tests.
2. "testng.xml attribute controlling parallel thread pool size" — in TestNG, this describes which of the following?
- A. TimeOut attribute.
- B. Thread-count.correct
- C. IRetryAnalyzer.
- D. @Ignore / enabled=false.
Why: thread-count: testng.xml attribute controlling parallel thread pool size.
3. "Soft/hard assertion comparing expected and actual values" — in TestNG, this describes which of the following?
- A. IRetryAnalyzer.
- B. @AfterSuite.
- C. AssertEquals.correct
- D. @Ignore / enabled=false.
Why: assertEquals: Soft/hard assertion comparing expected and actual values.
4. "Collects assertion failures and reports them at assertAll()" — in TestNG, this describes which of the following?
- A. TimeOut attribute.
- B. SoftAssert.correct
- C. @Ignore / enabled=false.
- D. @Test.
Why: SoftAssert: Collects assertion failures and reports them at assertAll().
5. "Fails a test if it exceeds the given milliseconds" — in TestNG, this describes which of the following?
- A. @Parameters.
- B. TimeOut attribute.correct
- C. @Ignore / enabled=false.
- D. Thread-count.
Why: timeOut attribute: Fails a test if it exceeds the given milliseconds.
6. "Injects values defined in testng.xml into a test method" — in TestNG, this describes which of the following?
- A. @Parameters.correct
- B. @AfterSuite.
- C. @Ignore / enabled=false.
- D. SoftAssert.
Why: @Parameters: Injects values defined in testng.xml into a test method.
7. "Skips a test from execution" — in TestNG, this describes which of the following?
- A. @Test.
- B. @Ignore / enabled=false.correct
- C. IRetryAnalyzer.
- D. AssertEquals.
Why: @Ignore / enabled=false: Skips a test from execution.
8. "Runs once after all tests in the suite finish" — in TestNG, this describes which of the following?
- A. @Parameters.
- B. IRetryAnalyzer.
- C. SoftAssert.
- D. @AfterSuite.correct
Why: @AfterSuite: Runs once after all tests in the suite finish.
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. "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.
11. 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.
12. 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. ExpectedExceptions asserts that a test throws a specific exception.correct
Why: The test fails if the declared exception is not thrown.
13. Identify the accurate statement about TestNG:
- A. DependsOnMethods makes one test run only after another test passes.correct
- B. DependsOnMethods causes the dependent test to run even if the prerequisite fails, by default.
- C. @BeforeClass runs before every individual test method.
- D. TestNG has no listener mechanism for reacting to test failures.
Why: Dependent tests are skipped if the prerequisite fails.
14. Which TestNG concept matches this description: "Injects values defined in testng.xml into a test method"?
- A. Thread-count.
- B. @Ignore / enabled=false.
- C. IRetryAnalyzer.
- D. @Parameters.correct
Why: @Parameters: Injects values defined in testng.xml into a test method.
15. In TestNG, which of the following is described as: "testng.xml attribute controlling parallel thread pool size"?
- A. IRetryAnalyzer.
- B. Thread-count.correct
- C. @Test.
- D. AssertEquals.
Why: thread-count: testng.xml attribute controlling parallel thread pool size.
16. In TestNG, which of the following is described as: "Injects values defined in testng.xml into a test method"?
- A. @Parameters.correct
- B. AssertEquals.
- C. Thread-count.
- D. TimeOut attribute.
Why: @Parameters: Injects values defined in testng.xml into a test method.
17. In TestNG, which of the following is described as: "Interface used to automatically retry failed tests"?
- A. TimeOut attribute.
- B. IRetryAnalyzer.correct
- C. AssertEquals.
- D. @AfterSuite.
Why: IRetryAnalyzer: Interface used to automatically retry failed tests.
18. In TestNG, which of the following is described as: "Soft/hard assertion comparing expected and actual values"?
- A. @AfterSuite.
- B. AssertEquals.correct
- C. @Test.
- D. SoftAssert.
Why: assertEquals: Soft/hard assertion comparing expected and actual values.
19. Which TestNG concept matches this description: "Interface used to automatically retry failed tests"?
- A. Thread-count.
- B. IRetryAnalyzer.correct
- C. @AfterSuite.
- D. SoftAssert.
Why: IRetryAnalyzer: Interface used to automatically retry failed tests.
20. Which TestNG concept matches this description: "Collects assertion failures and reports them at assertAll()"?
- A. AssertEquals.
- B. SoftAssert.correct
- C. @Test.
- D. TimeOut attribute.
Why: SoftAssert: Collects assertion failures and reports them at assertAll().