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. Assertions.assertThrows verifies that code throws an expected exception.
- B. Assumptions like assumeTrue abort a test (rather than fail it) when conditions are not met.
- C. @ParameterizedTest with sources like @ValueSource or @CsvSource runs a test with multiple inputs.
- 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.
2. In a test-strategy meeting, the question comes up: 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 statement about JUnit is NOT correct?
- A. JUnit 5 consists of the Platform, Jupiter, and Vintage modules.
- B. @BeforeEach runs before every test, and @BeforeAll runs once per class (static by default).
- C. JUnit 5 cannot run JUnit 4 tests under any circumstances.correct
- 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.
4. Identify the INCORRECT statement about JUnit:
- A. Assumptions like assumeTrue abort a test (rather than fail it) when conditions are not met.
- B. AssertThrows passes only if no exception is thrown.correct
- C. Assertions.assertThrows verifies that code throws an expected exception.
- D. @DisplayName provides human-readable test names in reports.
Why: The selected statement is false. The other options are accurate statements about JUnit.
5. Which of the following statements about JUnit is FALSE?
- A. JUnit 5 cannot run JUnit 4 tests under any circumstances.correct
- B. JUnit 5 supports dependency-injected parameters like TestInfo and TempDir in test methods.
- C. Assertions.assertThrows verifies that code throws an expected exception.
- D. @BeforeEach runs before every test, and @BeforeAll runs once per class (static by default).
Why: The selected statement is false. The other options are accurate statements about JUnit.