【发布时间】:2020-01-07 12:36:49
【问题描述】:
我有以下功能:
public class NorthboundApiLogicTest {
@Test
public void testIfParametersValuesAreCorrect() {
String body = "{\"exception\":\"world\",\"error\":\"Not Found\",\"message\":\"hello\""
+ ",\"timestamp\":\"2020-01-07T12:26:48.334386Z\",\"status\":\"404\"}";
try {
JSONAssert.assertEquals("{message:hello, exception:world, status:403, error:Not Found}",
body, false);
} catch (Exception e) {
System.err.println(e);
}
System.out.println(body);
}
}
我用 Maven 运行这个测试,奇怪的是它成功通过了。
但是,它不应该,因为我断言 status=403 但值是 404。我究竟做错了什么?
【问题讨论】:
-
请注意,抛出 JSONException 并且您处于捕获状态。