views:

67

answers:

1

I have a Silverlight 4 client running on a Facebook page hosted on Google App Engine. It's using gminifb to communicate with the Facebook API. The Silverlight client uses POST calls to the URIs for each method and passes the session information from Facebook with each call.

The project's growing and it would be super-useful if I could set up a unit-testing system to make a variety of the server calls so that when I make changes I can ensure everything else still works. I've worked with nUnit before and I like what I've read of PEX but I'm not sure how to apply them to this situation.

  1. What're the choices for creating a test system for this? Pros/cons of each?

  2. How do I get started setting something like this up?

+1  A: 

Solved. I did it as follows:

  1. Created a special user account to be used for testing on the server that bypassed the authentication. Only did this on the test environment by checking a debug flag in that environment's settings. This avoided creating any security hole in the live site (since the same debug flag will be false there.)

  2. Created a C#.NET solution to test each API call. The host project is a console app (no need for a GUI) with three reusable synchronous methods:
    SendFormRequest(WebRequest request, Dictionary<string,string> pairs),
    GetJsonFromResponse(HttpWebResponse response),
    and ResetAccount().
    These three methods allow the host project to make HTTP requests on the server and to read the JSON responses.

  3. Wrapped each server API call inside a method call in the host project.

  4. Created an nUnit test project in the solution. Then simply created tests that call each wrapper method in the host project, using different parameters and changing values on the server.

  5. Created a series of tests to verify correct error handling for invalid parameters and data.

It's working perfectly and has already identified a few minor issues that have been found. The result is immensely useful and will check for breaking changes on new deployments.

Nick Gotch