0
0
JUnittesting~10 mins

Why organization scales test suites in JUnit - Test Your Understanding

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

Complete the code to create a simple JUnit test method that checks if 5 is greater than 3.

JUnit
@Test
public void testNumberComparison() {
    assertTrue(5 [1] 3);
}
Drag options to blanks, or click blank then click option'
A<
B>
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes the test to fail.
2fill in blank
medium

Complete the code to assert that the string "hello" starts with "he".

JUnit
@Test
public void testStringStart() {
    assertTrue("hello".[1]("he"));
}
Drag options to blanks, or click blank then click option'
Acontains
BendsWith
CstartsWith
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using endsWith will check the end of the string, causing the test to fail.
3fill in blank
hard

Fix the error in the assertion that checks if two integers are equal.

JUnit
@Test
public void testEquality() {
    [1](10, 5 + 5);
}
Drag options to blanks, or click blank then click option'
AassertTrue
BassertNotNull
CassertFalse
DassertEquals
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertTrue with equality check is less clear and may cause confusion.
4fill in blank
hard

Fill both blanks to create a test that fails if the list is empty.

JUnit
@Test
public void testListNotEmpty() {
    List<String> items = List.of("apple", "banana");
    assertFalse(items.[1]() [2] 0);
}
Drag options to blanks, or click blank then click option'
Asize
BisEmpty
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using isEmpty() with assertFalse and '>' causes logical errors.
5fill in blank
hard

Fill all three blanks to create a test that checks if a map contains a key and its value is not null.

JUnit
@Test
public void testMapKeyAndValue() {
    Map<String, String> map = Map.of("key1", "value1");
    assertTrue(map.[1]("key1") && map.get("key1") [2] null && !map.get("key1").[3]());
}
Drag options to blanks, or click blank then click option'
AcontainsKey
B!=
CisEmpty
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using equals() to compare with null causes NullPointerException.