mercredi 20 mai 2015

Best approach to testing a complex web API?

Suppose I've built the API for a complex game; let's say it's a clone of Words with Friends, as an example. We will include all the complexity of having Google oauth'd users, multiple ongoing games, etc.

What is the best way to test such an API? Specifically:

  • I want to test user registration, login, adding/removing friends, etc. I also want to test game logic, etc. But to test game logic, I need to have users in the database, so testing game logic inherently depends on the user logic working. Do I load fixtures into the database before running the game logic tests (in a setup function, of course)? Is there a better way?

  • When testing user registration, I need to generate an oauth token. However, this can only be done with a real email and a real person clicking "OK" to get the token. How do I automate this?

  • When it comes to testing game logic, what is the best way to approach this? Should I just write a series of tests which mimic real player-vs-player gameplay? In other words, how would you test the game logic of Words with Friends?

Aucun commentaire:

Enregistrer un commentaire