0
0
JUnittesting~5 mins

assertAll for grouped assertions in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of assertAll in JUnit?

assertAll allows you to group multiple assertions together so that all are checked, and you see all failures at once instead of stopping at the first failure.

Click to reveal answer
beginner
How does assertAll improve test feedback compared to separate assertions?

It runs all assertions inside it and reports all failures together, so you get a complete picture of what went wrong in one test run.

Click to reveal answer
beginner
Write a simple example of assertAll with two assertions checking if 2+2 equals 4 and 3+3 equals 6.
assertAll("Math checks",
  () -> assertEquals(4, 2 + 2),
  () -> assertEquals(6, 3 + 3)
);
Click to reveal answer
intermediate
What happens if one assertion inside assertAll fails?

JUnit continues running the other assertions inside assertAll and reports all failures together after running them all.

Click to reveal answer
beginner
Can assertAll be used with lambda expressions in JUnit?

Yes, assertAll takes a heading and a list of lambda expressions, each containing an assertion to run.

Click to reveal answer
What is the main benefit of using assertAll in JUnit tests?
AIt stops test execution at the first failure
BIt runs all assertions and reports all failures together
CIt automatically fixes failed assertions
DIt runs assertions in parallel threads
Which syntax correctly uses assertAll in JUnit?
AassertAll("group", () -> assertEquals(1, 1), () -> assertTrue(true));
BassertAll(assertEquals(1, 1), assertTrue(true));
CassertAll(() -> assertEquals(1, 1), () -> assertTrue(true));
DassertAll("group", assertEquals(1, 1), assertTrue(true));
If one assertion fails inside assertAll, what happens next?
ATest stops immediately
BOnly the first failure is reported
CTest passes anyway
DRemaining assertions run and all failures reported
Which of these is NOT a valid use of assertAll?
AGrouping multiple assertions for better feedback
BRunning assertions sequentially and reporting all failures
CAutomatically retrying failed assertions
DUsing lambda expressions to define assertions
What type of arguments does assertAll accept for assertions?
ALambda expressions
BIntegers
CStrings
DBoolean values
Explain how assertAll helps improve test results when multiple checks are needed.
Think about how you want to see all problems at once instead of fixing one by one.
You got /4 concepts.
    Write a short example using assertAll to check that a string is not null and its length is 5.
    Use assertNotNull and assertEquals inside lambda expressions.
    You got /4 concepts.