Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Client driver

Neil Prosser edited this page · 42 revisions
Clone this wiki locally

The rest-client-driver is a library which simulates a RESTful service. You can set expectations on the HTTP requests you want to receive during a test.

Maven dependency

<dependency>
    <groupId>com.github.rest-driver</groupId>
    <artifactId>rest-client-driver</artifactId>
    <version>1.1.41</version>
    <scope>test</scope>
</dependency>

Example uses

We use JUnit's @Rule annotation to add the client-driver to a test.

@Rule
public ClientDriverRule driver = new ClientDriverRule();

The driver will have all expectations cleared before each test. In your test you can add expectations to the driver:

driver.addExpectation(onRequestTo("/blah"), giveEmptyResponse().withStatus(404));

At present the expectations are matched without considering the order and one expectation must be added for each URL that is called.

At the end of each test the driver checks whether there were any requests made that it wasn't expecting or whether any of the requests it did expect were unfulfilled. If there is any discrepancy it throws an instance of ClientDriverFailedExpectationException.

Something went wrong with that request. Please try again.