我应该使用什么 JUnit 命令来检查,预期的不等于实际的。

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

所以问题是:我应该使用什么 JUnit 命令来检查预期与实际不相等。例如我像这样使用 assertEquals

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

所以这里预期的变量是 2 但实际是 1 并且测试失败。我应该使用什么命令来使这个测试通过?

当然,还有简单的 assertNotEquals(),但我通常建议使用一个并且只断言你确实需要:assertThat!

assertThat(actual, is(expected));

或者,在您的情况下:

assertThat(actual, not(expected));

其中 is()not()hamcrest 完全按照其名称所暗示的匹配器。