在 JUnit 失败消息中使用十六进制

Use hexadecimal in JUnit failure messages

有没有办法配置 JUnit 在显示错误消息时以十六进制打印整数?

例如,有没有办法让 JUnit 显示这个

    Failure: does_not_touch_other_bits(PackedArrayTest): expected:<0xabcd1234> but was:<0>
Tests run: 1, Failures: 1

而不是这个

    Failure: does_not_touch_other_bits(PackedArrayTest): expected:<-1430689110> but was:<0>
Tests run: 1, Failures: 1

不,您不能将 JUnit 配置为将整数打印为十六进制值。

但您可以编写自己的 assertEqualsHex(int expected, int value) 方法。

另一种可能是你使用这个 assertMethod:

public static void assertEquals(String message, Object expected,
            Object actual)

并在消息参数中提供预期的十六进制值。