Search code examples
javajunitassert

What JUnit command i should use to check that, the expected is not equal to the actual.


So the question is: what JUnit command i should use to check that the expected is not equal to the actual. For example i use assertEquals like this

assertEquals(tr1.detectTriangle(), tr1.TR_EQUILATERAL);

So here expected variable is 2 but actual is 1 and test fails. What command i should use to make this test passed?


Solution

  • Of course, there is the simple assertNotEquals(), but I typically suggest to use the one and only assert you really need: assertThat!

    assertThat(actual, is(expected));
    

    or, in your case:

    assertThat(actual, not(expected));
    

    Where is() and not() are hamcrest matchers that do exactly what their names imply.