0
0
JUnittesting~10 mins

@DisplayName for readable names in JUnit - Interactive Code Practice

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

Complete 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'
A"Addition works correctly"
B'Addition works correctly'
CAddition works correctly
DAddition_works_correctly
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.
2fill in blank
medium

Complete 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'
A"Subtracting two numbers"
B'Subtracting two numbers'
CSubtracting two numbers
Dsubtracting_two_numbers
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes.
Not using quotes at all.
Using underscores instead of spaces.
3fill in blank
hard

Fix 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'
Amultiplication_test
BMultiplication test
C'Multiplication test'
D"Multiplication test"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes.
Not using any quotes.
Using underscores instead of spaces.
4fill in blank
hard

Fill 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'
A@Test
B"Division works correctly"
C@TestMethod
D'Division works correctly'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @TestMethod instead of @Test.
Using single quotes for display name.
Omitting the @Test annotation.
5fill in blank
hard

Fill 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'
A@Test
B"Modulo operation test"
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong annotation like @TestMethod.
Using single quotes for display name.
Using wrong expected value in assertEquals.