0
0
JUnittesting~10 mins

JUnit 4 vs JUnit 5 (Jupiter) differences - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to use the correct annotation for a test method in JUnit 5.

JUnit
@[1]
public void testAddition() {
    assertEquals(5, 2 + 3);
}
Drag options to blanks, or click blank then click option'
ATestMethod
BTest
CTestCase
DTestAnnotation
Attempts:
3 left
💡 Hint
Common Mistakes
Using @TestMethod which does not exist in JUnit 5.
Confusing with JUnit 4 imports.
2fill in blank
medium

Complete the code to disable a test method in JUnit 5.

JUnit
@Test
@[1]
public void testFeature() {
    // test code
}
Drag options to blanks, or click blank then click option'
ADisabled
BIgnore
CSkip
DIgnoreTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Ignore which is from JUnit 4.
Using @Skip which does not exist.
3fill in blank
hard

Fix the error in the JUnit 5 lifecycle method annotation for setup before all tests.

JUnit
@Before[1]
public static void initAll() {
    // initialization code
}
Drag options to blanks, or click blank then click option'
ASuite
BBeforeClass
CAllTests
DAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeClass which is from JUnit 4.
Using incorrect suffixes like 'Suite' or 'AllTests'.
4fill in blank
hard

Fill both blanks to correctly write a parameterized test in JUnit 5.

JUnit
@[1]
@[2](value = {"apple", "banana", "cherry"})
void testFruits(String fruit) {
    assertNotNull(fruit);
}
Drag options to blanks, or click blank then click option'
AParameterizedTest
BValueSource
CTest
DCsvSource
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Test instead of @ParameterizedTest.
Using @CsvSource when only simple values are needed.
5fill in blank
hard

Fill all three blanks to write a JUnit 5 test method that asserts an exception is thrown.

JUnit
@Test
void testException() {
    Exception exception = assertThrows([1].class, () -> {
        throw new [2]("Error");
    });
    assertEquals("[3]", exception.getMessage());
}
Drag options to blanks, or click blank then click option'
AIllegalArgumentException
CError
DRuntimeException
Attempts:
3 left
💡 Hint
Common Mistakes
Using different exception classes in assertThrows and throw statement.
Mismatching the exception message string.