在我的单元测试中,我目前有以下代码:
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);
我如何告诉 HttpUnit 不会因为 http 状态 4xx 而失败?