0
0
JUnittesting~10 mins

assertAll for grouped assertions 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 group multiple assertions using assertAll.

JUnit
assertAll([1]);
Drag options to blanks, or click blank then click option'
A"Test group", () -> { assertEquals(5, sum); assertTrue(flag); }
B"Test group", () -> { assertEquals(5, sum); }
CassertEquals(5, sum)
DassertTrue(flag)
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertAll with only one assertion without a lambda.
Passing assertions outside a lambda to assertAll.
2fill in blank
medium

Complete 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'
Atotal
Bvalue
Ccount
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not defined or unrelated.
Confusing variable names like total or count.
3fill in blank
hard

Fix 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'
AassertTrue(list.contains('item'))
BassertTrue(list.contains(item))
CassertTrue(list.contains("item"))
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings which is invalid in Java.
Using undefined variable item without quotes.
4fill in blank
hard

Fill 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'
AassertEquals(4, result)
BassertTrue(isValid)
CassertFalse(isEmpty)
DassertNull(value)
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing assertFalse or assertNull where assertTrue is expected.
Using assertions that do not match the test intent.
5fill in blank
hard

Fill 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'
AassertNotNull(obj)
BassertEquals(7, count)
CassertTrue(flag)
DassertFalse(error)
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertFalse instead of assertTrue for the flag.
Missing the not-null check for the object.