In my unit test, I currently have this code:
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);
This is quite verbose. I would prefer to use something like this:
WebConversation wc = new WebConversation();
wc.doNotFail(); // <= does not exist
assertThat(wc.getResponse(new GetMethodWebRequest("http://myurl")).getResponseCode()).isEqualTo(403);
How can I tell HttpUnit to not fail for http status 4xx?
You can use (for each test):
wc.setExceptionsThrownOnErrorStatus(false);
or (for all tests):
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.