JUnit 5 interview questions — Hard
101 hard-level JUnit 5 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
JUnit 5 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 JUnit, which of the following is a false statement?
- A. Assumptions that fail mark the test as failed in the report.correct
- B. Assertions.assertThrows verifies that code throws an expected exception.
- C. JUnit 5 supports dependency-injected parameters like TestInfo and TempDir in test methods.
- D. @Tag allows filtering which tests run, similar to TestNG groups.
Why: The selected statement is false. The other options are accurate statements about JUnit.
2. While onboarding a junior QA, you explain: JUnit 5's assertAll() is used to:
- A. Stop at first failure.
- B. Group assertions so all are evaluated and reported together.correct
- C. Skip a test.
- D. Measure time.
Why: assertAll() evaluates all grouped assertions and reports every failure.
3. Which of the following statements about JUnit is FALSE?
- A. @Nested classes group related tests hierarchically inside a test class.
- B. @ParameterizedTest with sources like @ValueSource or @CsvSource runs a test with multiple inputs.
- C. @DisplayName provides human-readable test names in reports.
- D. Parameterized tests require the JUnit 4 @RunWith(Parameterized.class) runner in JUnit 5.correct
Why: The selected statement is false. The other options are accurate statements about JUnit.
4. Which statement about JUnit is NOT correct?
- A. @BeforeEach runs before every test, and @BeforeAll runs once per class (static by default).
- B. Parameterized tests require the JUnit 4 @RunWith(Parameterized.class) runner in JUnit 5.correct
- C. JUnit 5 consists of the Platform, Jupiter, and Vintage modules.
- D. @DisplayName provides human-readable test names in reports.
Why: The selected statement is false. The other options are accurate statements about JUnit.
5. Identify the INCORRECT statement about JUnit:
- A. JUnit 5 has no mechanism for tagging or filtering tests.correct
- B. Assumptions like assumeTrue abort a test (rather than fail it) when conditions are not met.
- C. @Tag allows filtering which tests run, similar to TestNG groups.
- D. @Nested classes group related tests hierarchically inside a test class.
Why: The selected statement is false. The other options are accurate statements about JUnit.