Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a readable name to the test method using @DisplayName.
JUnit
@Test @DisplayName([1]) void testAddition() { assertEquals(5, 2 + 3); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use quotes around the display name string.
Using single quotes instead of double quotes.
Passing a variable or unquoted text.
✗ Incorrect
The @DisplayName annotation requires a string literal in double quotes to provide a readable name.
2fill in blank
mediumComplete the code to add a display name that describes the test purpose.
JUnit
@Test @DisplayName([1]) void testSubtraction() { assertEquals(2, 5 - 3); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes.
Not using quotes at all.
Using underscores instead of spaces.
✗ Incorrect
The display name must be a string literal in double quotes to be valid.
3fill in blank
hardFix the error in the @DisplayName annotation to make the test method name readable.
JUnit
@Test @DisplayName([1]) void testMultiplication() { assertEquals(6, 2 * 3); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes.
Not using any quotes.
Using underscores instead of spaces.
✗ Incorrect
The @DisplayName annotation requires a string literal in double quotes to be valid.
4fill in blank
hardFill both blanks to add a display name and a test annotation correctly.
JUnit
[1] @DisplayName([2]) void testDivision() { assertEquals(2, 6 / 3); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @TestMethod instead of @Test.
Using single quotes for display name.
Omitting the @Test annotation.
✗ Incorrect
Use @Test annotation and a string literal in double quotes for @DisplayName.
5fill in blank
hardFill all three blanks to create a test method with @Test, @DisplayName, and a proper assertion.
JUnit
[1] @DisplayName([2]) void testModulo() { assertEquals([3], 10 % 3); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong annotation like @TestMethod.
Using single quotes for display name.
Using wrong expected value in assertEquals.
✗ Incorrect
Use @Test annotation, a string literal for display name, and the correct assertion value 1 for 10 % 3.