slartidan
slartidan

Reputation: 21586

How to tell HttpUnit to not fail for http status 4xx?

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?

Upvotes: 0

Views: 22

Answers (1)

slartidan
slartidan

Reputation: 21586

You can use (for each test):

    wc.setExceptionsThrownOnErrorStatus(false);

or (for all tests):

    HttpUnitOptions.setExceptionsThrownOnScriptError(false);

Upvotes: 0

Related Questions