0
0
JUnittesting~5 mins

assertEquals in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does assertEquals do in JUnit?

assertEquals checks if two values are the same. If they are not, the test fails.

Click to reveal answer
beginner
How do you write assertEquals to compare expected and actual values?

Use assertEquals(expected, actual). The first value is what you expect, the second is what your code gives.

Click to reveal answer
beginner
What happens if assertEquals fails during a test?

The test stops and reports failure. It shows the expected and actual values to help find the problem.

Click to reveal answer
intermediate
Can assertEquals compare objects in JUnit?

Yes, it compares objects using their equals() method. Objects must override equals() properly for correct comparison.

Click to reveal answer
beginner
Why is the order of parameters important in assertEquals(expected, actual)?

The order matters because failure messages show expected first, then actual. This helps understand test results clearly.

Click to reveal answer
What is the correct order of parameters in assertEquals?
Aactual only
Bactual, expected
Cexpected, actual
Dexpected only
What happens if assertEquals finds values are not equal?
ATest fails and stops
BTest ignores the difference
CTest passes
DTest retries automatically
Which method does assertEquals use to compare objects?
AcompareTo()
BhashCode()
CtoString()
Dequals()
Which of these is a valid assertEquals statement in JUnit?
AassertEquals()
BassertEquals(5, calculateSum())
CassertEquals(5)
DassertEquals(calculateSum(), 5)
Why should you use assertEquals instead of assertTrue(a == b)?
AassertEquals gives clearer failure messages
BassertTrue is faster
CassertEquals ignores differences
DassertTrue works only for strings
Explain how assertEquals works in JUnit and why the order of parameters matters.
Think about how test results help you find bugs.
You got /5 concepts.
    Describe how assertEquals compares objects and what you need to ensure for correct comparison.
    Consider how Java compares two objects by default.
    You got /4 concepts.