在我的单元测试中,我目前有这段代码:
int responseCode;
try {
WebResponse response = new WebConversation().getResponse(new GetMethodWebRequest("http://myurl"));
responseCode = response.getResponseCode();
} catch (HttpException e) {
responseCode = e.getResponseCode();
}
assertThat(responseCode).isEqualTo(403);
这非常冗长。我更喜欢使用这样的东西:
WebConversation wc = new WebConversation();
wc.doNotFail(); // <= does not exist
assertThat(wc.getResponse(new GetMethodWebRequest("http://myurl")).getResponseCode()).isEqualTo(403);
如何判断http状态4xx的HttpUnit没有失败?
答案 0 :(得分:0)
您可以使用(针对每个测试):
wc.setExceptionsThrownOnErrorStatus(false);
或(对于所有测试):
HttpUnitOptions.setExceptionsThrownOnScriptError(false);