How to unit test a web service

H

To test your web service, you can use Smock. Smock compares your request with the response by XML files. You just need a response.xml file with your response and a request.xml file with your request.

Maven:

<dependency>
    <groupId>net.javacrumbs</groupId>
    <artifactId>smock-easymock</artifactId>
    <version>0.5</version>
</dependency>

Jar:

http://mvnrepository.com/artifact/net.javacrumbs/smock-easymock

Code:

private AirlineEndpoint endpoint = new AirlineEndpoint();

@Test
public void testCompare() throws Exception {
    GetFlightsRequest request = createRequest("request.xml", GetFlightsRequest.class);
    GetFlightsResponse response = endpoint.getFlights(request);
    validate(response).andExpect(message("response.xml"));
}

More info:

https://code.google.com/p/smock/

Add comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud

Categories