views:

44

answers:

1

We've written a .NET wrapper API for a set of web services. All this does is make requests and return JSON data. What's a good way to build a test framework for this? I can't think of how to do unit tests since I'd have to know the expected JSON string I'm getting back and that's very dynamic and complex. I thought of doing a WebTest but that just hits a page and crawls URLs. Any ideas out there?

For example, it makes a request like:

http://supersecretwebsite.com/services/library?command=somecommand&sort_order=ASC&sort_by=MODIFIED_DATE&page_number=0&token=myapikey&get_item_count=true

And returns JSON:

{"videos":[{"id":230482394920,"name":"foobarrr","shortDescription":"foo"],"page_number":0,"page_size":100,"total_count":0}
A: 

One solution would be to Mock the service with a mocking framework. You can setup the mocks to return the piece of JSON that you're testing against. This way you can easily isolate the behavior of the web service, without having to make the calls to it.

Gavin Miller