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. "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. "Collects assertion failures and reports them at assertAll()" — in TestNG, this describes which of the following?
- A. Thread-count.
- B. SoftAssert.correct
- C. TimeOut attribute.
- D. @Parameters.
Why: SoftAssert: Collects assertion failures and reports them at assertAll().
3. "Soft/hard assertion comparing expected and actual values" — in TestNG, this describes which of the following?
- A. AssertEquals.correct
- B. IRetryAnalyzer.
- C. Thread-count.
- D. @AfterSuite.
Why: assertEquals: Soft/hard assertion comparing expected and actual values.
4. "Interface used to automatically retry failed tests" — in TestNG, this describes which of the following?
- A. AssertEquals.
- B. @Ignore / enabled=false.
- C. IRetryAnalyzer.correct
- D. @AfterSuite.
Why: IRetryAnalyzer: Interface used to automatically retry failed tests.
5. "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.
6. "Skips a test from execution" — in TestNG, this describes which of the following?
- A. @Ignore / enabled=false.correct
- B. @AfterSuite.
- C. TimeOut attribute.
- D. IRetryAnalyzer.
Why: @Ignore / enabled=false: Skips a test from execution.
7. 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.
8. Identify the accurate statement about TestNG:
- A. Higher priority values run before lower priority values.
- B. Testng.xml files cannot pass parameters to test methods.
- C. @BeforeClass runs before every individual test method.
- D. TestNG supports parallel execution at methods, classes, tests, or instances level via the parallel attribute.correct
Why: parallel + thread-count in testng.xml enable concurrency.
9. Which of the following statements about TestNG is TRUE?
- A. TestNG has no listener mechanism for reacting to test failures.
- B. TestNG cannot run tests in parallel without a third-party plugin.
- C. @BeforeClass runs before every individual test method.
- D. Testng.xml defines suites, tests, groups, parameters, and parallel execution settings.correct
Why: The XML file orchestrates what runs and how.
10. Which statement correctly describes TestNG?
- A. @BeforeMethod runs before each test method, while @BeforeClass runs once per class.correct
- B. Higher priority values run before lower priority values.
- C. TestNG has no listener mechanism for reacting to test failures.
- D. TestNG cannot run tests in parallel without a third-party plugin.
Why: TestNG configuration annotations control setup granularity.
11. In TestNG, which of the following is described as: "testng.xml attribute controlling parallel thread pool size"?
- A. IRetryAnalyzer.
- B. @Test.
- C. @Parameters.
- D. Thread-count.correct
Why: thread-count: testng.xml attribute controlling parallel thread pool size.
12. Which TestNG concept matches this description: "Injects values defined in testng.xml into a test method"?
- A. SoftAssert.
- B. @Parameters.correct
- C. Thread-count.
- D. @Test.
Why: @Parameters: Injects values defined in testng.xml into a test method.
13. Which TestNG concept matches this description: "testng.xml attribute controlling parallel thread pool size"?
- A. Thread-count.correct
- B. @Parameters.
- C. @Ignore / enabled=false.
- D. SoftAssert.
Why: thread-count: testng.xml attribute controlling parallel thread pool size.
14. Which TestNG concept matches this description: "Fails a test if it exceeds the given milliseconds"?
- A. @Test.
- B. TimeOut attribute.correct
- C. @Parameters.
- D. @AfterSuite.
Why: timeOut attribute: Fails a test if it exceeds the given milliseconds.
15. Which TestNG concept matches this description: "Soft/hard assertion comparing expected and actual values"?
- A. @Parameters.
- B. SoftAssert.
- C. Thread-count.
- D. AssertEquals.correct
Why: assertEquals: Soft/hard assertion comparing expected and actual values.
16. In TestNG, which of the following is described as: "Injects values defined in testng.xml into a test method"?
- A. @Ignore / enabled=false.
- B. @Test.
- C. IRetryAnalyzer.
- D. @Parameters.correct
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. IRetryAnalyzer.correct
- B. Thread-count.
- C. @AfterSuite.
- D. AssertEquals.
Why: IRetryAnalyzer: Interface used to automatically retry failed tests.
18. 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.
19. In TestNG, which of the following is described as: "Fails a test if it exceeds the given milliseconds"?
- A. @Test.
- B. AssertEquals.
- C. TimeOut attribute.correct
- D. @AfterSuite.
Why: timeOut attribute: Fails a test if it exceeds the given milliseconds.
20. In the context of TestNG, which of the following is a correct statement?
- A. Higher priority values run before lower priority values.
- B. The priority attribute orders test method execution, lower values first.correct
- C. A @DataProvider may only return a single row of data.
- D. Testng.xml files cannot pass parameters to test methods.
Why: Default priority is 0; ties run in alphabetical order.