Complete the code to use the correct annotation for a test method in JUnit 5.
@[1] public void testAddition() { assertEquals(5, 2 + 3); }
In JUnit 5, the test method is annotated with @Test from the org.junit.jupiter.api package.
Complete the code to disable a test method in JUnit 5.
@Test
@[1]
public void testFeature() {
// test code
}In JUnit 5, to disable a test method, use the @Disabled annotation.
Fix the error in the JUnit 5 lifecycle method annotation for setup before all tests.
@Before[1]
public static void initAll() {
// initialization code
}In JUnit 5, the annotation for setup before all tests is @BeforeAll. It replaces JUnit 4's @BeforeClass.
Fill both blanks to correctly write a parameterized test in JUnit 5.
@[1] @[2](value = {"apple", "banana", "cherry"}) void testFruits(String fruit) { assertNotNull(fruit); }
In JUnit 5, parameterized tests use @ParameterizedTest and @ValueSource to supply values.
Fill all three blanks to write a JUnit 5 test method that asserts an exception is thrown.
@Test
void testException() {
Exception exception = assertThrows([1].class, () -> {
throw new [2]("Error");
});
assertEquals("[3]", exception.getMessage());
}This test checks that an IllegalArgumentException is thrown with the message "Error".