Testing RESTful applications

Developing a RESTful application basically comes down to developing one server- and one or more client applications. A recurring phase in application development is testing. When developing automated tests involving client-server communication the need for “mocking” will soon rise as the client and server applications must each be tested in their own development cycle.

With our new component “Mockingbird” we found a way of reusing server integration test results for the benefit of client tests and so created a mocked interface of the server’s REST services.

A test development cycle comes down to the following steps:

REST server application:

1. A server integration test is created for a REST service using the Wiztools restclient.

2. The integration test uses the Mockingbird component to translate the Wiztools Response object to xml. This xml is saved as a test scenario.

3. During the build phase after the integration tests have been run, the saved scenario’s are packaged in a jar and exported to a central repository.

REST client application:

4. The client application includes the test scenario’s jar in its test classpath.

5. A client test is created using the Mockingbird “server” with a scenario suitable for the test.



 

This figure shows the main advantage of this way of developing client- and server tests: the applications can be developed mostly independent of each other. For the client only a static dependency on the test scenario’s is required. A separate team for each application is now within the possibilities of team positioning.

With every server application release, a new version of the test scenario’s will also become available for the clients. Thus omitting the need for manual mock scenario maintenance, generally a huge recurring cost during the application lifecycle. Using these new scenario’s will immediately give feedback which service calls must be changed to connect with the newest server app.