JUnit 5 interview questions — Medium

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

What this covers

JUnit 5 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.

Other levels:Hard (101)Easy (98)

20 example questions

  1. 1. "Groups assertions so all are evaluated and failures reported together" — in JUnit, this describes which of the following?

    • A. AssertAll.correct
    • B. @Timeout.
    • C. @Disabled.
    • D. @Test.

    Why: assertAll: Groups assertions so all are evaluated and failures reported together.

  2. 2. Which JUnit 5 annotation runs the same test repeatedly with different argument sets?

    • A. @RepeatedTest.
    • B. @ParameterizedTest with a source (e.g., @ValueSource).correct
    • C. @BeforeEach.
    • D. @Disabled.

    Why: @ParameterizedTest combined with a source (@ValueSource, @CsvSource, @MethodSource, …) runs the test once per provided argument set.

  3. 3. Which of the following statements about JUnit is TRUE?

    • A. Assumptions that fail mark the test as failed in the report.
    • B. Parameterized tests require the JUnit 4 @RunWith(Parameterized.class) runner in JUnit 5.
    • C. JUnit 5 consists of the Platform, Jupiter, and Vintage modules.correct
    • D. JUnit 5 tests must extend a base TestCase class.

    Why: Jupiter is the new API; Vintage runs JUnit 4 tests on the platform.

  4. 4. "Marks a Jupiter test method" — in JUnit, this describes which of the following?

    • A. @CsvSource.
    • B. @Test.correct
    • C. @RepeatedTest.
    • D. TestInfo.

    Why: @Test: Marks a Jupiter test method.

  5. 5. Which statement correctly describes JUnit?

    • A. AssertThrows passes only if no exception is thrown.
    • B. @BeforeAll runs before every single test method.
    • C. JUnit 5 has no mechanism for tagging or filtering tests.
    • D. JUnit 5 consists of the Platform, Jupiter, and Vintage modules.correct

    Why: Jupiter is the new API; Vintage runs JUnit 4 tests on the platform.

  6. 6. "Skips a test or class with an optional reason" — in JUnit, this describes which of the following?

    • A. @Disabled.correct
    • B. @ExtendWith.
    • C. @RepeatedTest.
    • D. @Test.

    Why: @Disabled: Skips a test or class with an optional reason.

  7. 7. In a CI/CD pipeline review, consider this: Which JUnit 5 annotation runs a test with multiple argument sets?

    • A. @RepeatedTest.
    • B. @ParameterizedTest with a source.correct
    • C. @BeforeEach.
    • D. @Disabled.

    Why: @ParameterizedTest + a source runs once per argument set.

  8. 8. "Registers extensions such as MockitoExtension" — in JUnit, this describes which of the following?

    • A. TestInfo.
    • B. @Disabled.
    • C. @ExtendWith.correct
    • D. @RepeatedTest.

    Why: @ExtendWith: Registers extensions such as MockitoExtension.

  9. 9. "Runs a test a fixed number of times" — in JUnit, this describes which of the following?

    • A. @RepeatedTest.correct
    • B. @ExtendWith.
    • C. @Disabled.
    • D. TestInfo.

    Why: @RepeatedTest: Runs a test a fixed number of times.

  10. 10. Identify the accurate statement about JUnit:

    • A. AssertThrows passes only if no exception is thrown.
    • B. @BeforeEach runs before every test, and @BeforeAll runs once per class (static by default).correct
    • C. Assumptions that fail mark the test as failed in the report.
    • D. JUnit 5 has no mechanism for tagging or filtering tests.

    Why: Lifecycle annotations were renamed from JUnit 4's @Before/@BeforeClass.

  11. 11. Which JUnit concept matches this description: "Supplies inline CSV rows to a parameterized test"?

    • A. @ExtendWith.
    • B. AssertAll.
    • C. @CsvSource.correct
    • D. TestInfo.

    Why: @CsvSource: Supplies inline CSV rows to a parameterized test.

  12. 12. In the context of JUnit, which of the following is a correct statement?

    • A. @BeforeAll runs before every single test method.
    • B. @ParameterizedTest with sources like @ValueSource or @CsvSource runs a test with multiple inputs.correct
    • C. Parameterized tests require the JUnit 4 @RunWith(Parameterized.class) runner in JUnit 5.
    • D. JUnit 5 tests must extend a base TestCase class.

    Why: Parameterized tests replace repetitive copies of the same test.

  13. 13. In JUnit, which of the following is described as: "Groups assertions so all are evaluated and failures reported together"?

    • A. TestInfo.
    • B. AssertAll.correct
    • C. @Disabled.
    • D. @Timeout.

    Why: assertAll: Groups assertions so all are evaluated and failures reported together.

  14. 14. In JUnit, which of the following is described as: "Supplies inline CSV rows to a parameterized test"?

    • A. @RepeatedTest.
    • B. TestInfo.
    • C. @ExtendWith.
    • D. @CsvSource.correct

    Why: @CsvSource: Supplies inline CSV rows to a parameterized test.

  15. 15. Which JUnit concept matches this description: "Injected object describing the current test"?

    • A. @Timeout.
    • B. TestInfo.correct
    • C. @Test.
    • D. @ExtendWith.

    Why: TestInfo: Injected object describing the current test.

  16. 16. Which JUnit concept matches this description: "Fails a test exceeding a time limit"?

    • A. AssertAll.
    • B. @Timeout.correct
    • C. @Disabled.
    • D. @RepeatedTest.

    Why: @Timeout: Fails a test exceeding a time limit.

  17. 17. In JUnit, which of the following is described as: "Registers extensions such as MockitoExtension"?

    • A. @ExtendWith.correct
    • B. TestInfo.
    • C. @CsvSource.
    • D. @Timeout.

    Why: @ExtendWith: Registers extensions such as MockitoExtension.

  18. 18. Regarding JUnit, which statement is correct?

    • A. @ParameterizedTest with sources like @ValueSource or @CsvSource runs a test with multiple inputs.correct
    • B. JUnit 5 has no mechanism for tagging or filtering tests.
    • C. AssertThrows passes only if no exception is thrown.
    • D. @BeforeAll runs before every single test method.

    Why: Parameterized tests replace repetitive copies of the same test.

  19. 19. Which JUnit concept matches this description: "Runs a test a fixed number of times"?

    • A. AssertAll.
    • B. @RepeatedTest.correct
    • C. @Disabled.
    • D. @Timeout.

    Why: @RepeatedTest: Runs a test a fixed number of times.

  20. 20. Which JUnit concept matches this description: "Registers extensions such as MockitoExtension"?

    • A. AssertAll.
    • B. @ExtendWith.correct
    • C. @CsvSource.
    • D. TestInfo.

    Why: @ExtendWith: Registers extensions such as MockitoExtension.

Related Automation Testing topics