0
0
JUnittesting~5 mins

assertNotEquals in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does assertNotEquals check in a JUnit test?
assertNotEquals checks that two values are NOT equal. If they are equal, the test fails.
Click to reveal answer
beginner
How do you write assertNotEquals to check that 5 is not equal to 3?
Use assertNotEquals(5, 3); in your test method.
Click to reveal answer
beginner
What happens if assertNotEquals compares two equal values?
The test fails and JUnit reports an assertion error because the values should not be equal.
Click to reveal answer
intermediate
Can assertNotEquals be used to compare objects in JUnit?
Yes, it compares objects using their equals() method to check if they are not equal.
Click to reveal answer
beginner
Why is assertNotEquals useful in testing?
It helps confirm that two values or objects are different, ensuring the code does not produce unwanted equal results.
Click to reveal answer
What will happen if assertNotEquals(10, 10) is executed in a JUnit test?
AThe test passes
BThe test throws an exception unrelated to assertion
CThe test is skipped
DThe test fails
Which method does assertNotEquals use to compare objects?
Aequals() method
B== operator
ChashCode() method
DtoString() method
What is the correct syntax to add a failure message in assertNotEquals?
AassertNotEquals(message, expected, actual);
BassertNotEquals(expected, actual, message);
CassertNotEquals(expected, message, actual);
DassertNotEquals(actual, expected, message);
Which JUnit version introduced assertNotEquals?
AJUnit 3
BJUnit 5
CJUnit 4
DJUnit 2
If you want to check two strings are not equal ignoring case, can you use assertNotEquals directly?
AYes, it ignores case by default
BNo, you must compare ignoring case manually
CYes, but only in JUnit 5
DNo, you must use assertNotSame instead
Explain how assertNotEquals works in JUnit and when you would use it.
Think about confirming two things should not match in your test.
You got /4 concepts.
    Describe the difference between assertEquals and assertNotEquals in JUnit.
    One checks sameness, the other checks difference.
    You got /4 concepts.