Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to group multiple assertions using assertAll.
JUnit
assertAll([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertAll with only one assertion without a lambda.
Passing assertions outside a lambda to assertAll.
✗ Incorrect
The assertAll method takes a heading string and a lambda containing multiple assertions grouped together.
2fill in blank
mediumComplete the code to group two assertions inside assertAll.
JUnit
assertAll("Check values", () -> { assertEquals(10, [1]); assertTrue(active); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not defined or unrelated.
Confusing variable names like total or count.
✗ Incorrect
The variable sum is the one being checked for equality with 10.
3fill in blank
hardFix the error in the assertAll usage by completing the blank.
JUnit
assertAll("Multiple checks", () -> { assertEquals(3, list.size()); [1] });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings which is invalid in Java.
Using undefined variable
item without quotes.✗ Incorrect
The assertion must check if the list contains the string "item" using double quotes.
4fill in blank
hardFill both blanks to correctly group two assertions with assertAll.
JUnit
assertAll("Group assertions", () -> { [1]; [2]; });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing assertFalse or assertNull where assertTrue is expected.
Using assertions that do not match the test intent.
✗ Incorrect
The first blank is an equality check, the second blank checks a boolean condition.
5fill in blank
hardFill all three blanks to correctly write grouped assertions with assertAll.
JUnit
assertAll("Test all", () -> { [1]; [2]; [3]; });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertFalse instead of assertTrue for the flag.
Missing the not-null check for the object.
✗ Incorrect
The grouped assertions check that the object is not null, count equals 7, and flag is true.