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?✗ Incorrect
assertNotEquals expects values to be different. Since 10 equals 10, the test fails.Which method does
assertNotEquals use to compare objects?✗ Incorrect
assertNotEquals uses the equals() method to check if objects are not equal.What is the correct syntax to add a failure message in
assertNotEquals?✗ Incorrect
The message comes first:
assertNotEquals(String message, Object unexpected, Object actual).Which JUnit version introduced
assertNotEquals?✗ Incorrect
assertNotEquals was introduced in JUnit 4.If you want to check two strings are not equal ignoring case, can you use
assertNotEquals directly?✗ Incorrect
assertNotEquals uses equals() which is case sensitive. For ignoring case, compare manually.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.