3

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?

  • assertNotEquals or assertFalse should do it. If the method throws an exception you should add expected value to the @Test annotation. – duffymo Jul 09 '18 at 13:56
  • Duplicate of https://stackoverflow.com/questions/1096650/why-doesnt-junit-provide-assertnotequals-methods – olikaf Jul 09 '18 at 13:57

1 Answers1

5

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248