JUnit 5 Testing — Concept Check
Questions on JUnit 5 Testing. JUnit 5 is the modern Java testing framework — annotations, parameterized tests, nested tests, and rich assertions for production-quality test suites.
Questions in this quiz
8 questions on JUnit 5 Testing — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a JUnit 5 test class, what is the purpose of the @BeforeEach annotation?
- ATo run setup code before each test method
- BTo run teardown code after each test method
- CTo run setup code once before all test methods
- DTo skip a test method
2.A developer uses @ParameterizedTest with @ValueSource to test a method. What is the benefit of this approach?
- AIt automatically skips tests with invalid arguments
- BIt prevents the need for assertions in the test method
- CIt ensures tests run in parallel for faster execution
- DIt allows testing with multiple arguments in a single test method
3.A test method annotated with @Test is not executing. What could be the reason?
- AThe method is private
- BThe method has no assertions
- CThe method is static
- DThe method is annotated with @Disabled
4.What happens if an assertion fails in a JUnit 5 test method using assertAll?
- AOnly the failed assertion is reported
- BThe test is skipped
- CAll assertions are evaluated, and failures are reported together
- DThe test stops at the first failure
5.In JUnit 5, which annotation is used to give a test method a custom name in reports?
- A@TestName
- B@ReportName
- C@CustomName
- D@DisplayName
6.A developer uses @Nested classes in a JUnit 5 test. What advantage does this provide?
- AIt makes tests run faster
- BIt allows grouping related tests and sharing setup code
- CIt ensures tests run in a specific order
- DIt automatically generates test reports
7.A test using AssertJ fails with a clear error message. Why might AssertJ be preferred over JUnit assertions?
- AIt automatically fixes assertion failures
- BIt provides fluent and readable assertions with better error messages
- CIt integrates directly with all Java IDEs
- DIt requires less setup in test classes
8.What is the role of @AfterAll in a JUnit 5 test class?
- ATo run setup code before all test methods in the class
- BTo run cleanup code once after all test methods in the class
- CTo run cleanup code after each test method
- DTo skip all test methods in the class