0
0
JUnittesting~10 mins

assertNotEquals in JUnit - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that two strings are not equal using assertNotEquals in JUnit. It verifies that the actual output differs from an incorrect expected value.

Test Code - JUnit 5
JUnit
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Test;

public class NotEqualsTest {
    @Test
    public void testStringsAreNotEqual() {
        String actual = "Hello World";
        String wrongExpected = "Hello Jupiter";
        assertNotEquals(wrongExpected, actual, "Strings should not be equal");
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsJUnit test runner initialized-PASS
2Runs testStringsAreNotEqual methodMethod execution begins-PASS
3Assigns actual = "Hello World"Variable actual holds "Hello World"-PASS
4Assigns wrongExpected = "Hello Jupiter"Variable wrongExpected holds "Hello Jupiter"-PASS
5Calls assertNotEquals(wrongExpected, actual, "Strings should not be equal")Comparing "Hello Jupiter" and "Hello World"Verify that wrongExpected != actualPASS
6Test completes successfullyNo exceptions thrown-PASS
Failure Scenario
Failing Condition: If actual and wrongExpected strings are equal
Execution Trace Quiz - 3 Questions
Test your understanding
What does assertNotEquals verify in this test?
AThat the actual string is null
BThat the two strings are the same
CThat the two strings are different
DThat the expected string is empty
Key Result
Use assertNotEquals to confirm two values are different, helping catch unexpected equality bugs.