views:

50

answers:

1

I have an assembly which wraps the functionality of an external live web service.

How do I go about testing this web service effectively. Should I create a stub of the web service or should I write tests that send and receive live data to the web service?

The problem I have with the second approach is that if I send and expect real data from the web service then I can't assert the results each time as they might change!

A: 

If the wrapper only forwards the calls to the web services with no conditional logic at all, there’s no point in creating tests against it that don’t go through the real web service. In this case you should create one test for each operation which should only test the ability to reach the web service and come back without unexpected errors. The data returned really don’t matter. This is an integration test between your wrapper and the web service.

If your wrapper includes conditional logic, then it may be a good idea to create tests that exercise all the paths. It’ll be easier to test these cases if you do not depend on the real web service.

For testing the client code (the code that calls the wrapper), you should stub the wrapper or stub the web service. This will give you the control you need to guarantee the client always receives the same output given the same input.

Alfred Myers