Thursday, December 29, 2011

Test Driven API Development Thoughts


This was the basis for my lightning talk at #nodedc on December 14, 2011. It received positive feedback.



I wish I was better at Test Driven Development, I guess most developers do to. For me Rails started it, jQuery pushed it, but I still don't do it. But I'm trying. I'm talking build the test, then write the code. I may have a way to do the walk.

I have this idea for TDD for APIs. I want to take the idea of TDD outside the realm of a language or framework. In consuming an API the underlying language does not matter. Therefore, using TDD for developing APIs or developing with APIs should be outside the language or framework.

This project could also be a template for good practices in creating RESTful API. For example, a RESTful API is suppose to be about one resource. While that is good in theory, in practice it often works out differently. So however the design works, it needs flexibility.

There are probably three part to the project: an engine, a reporter and builder. The engine would read a json message, run the tests and report back. The builder would create the json message for the engine. The builder form would allow you to enter a URL/resource and test it. The result would be filled into the expect result field, which could be overwritten. This information could be used for documentation as well.

It could be especially useful for apps that depend on a variety of APIs from different sources. Run the tests regularly to make certain the APIs are still functioning as expected.

Or maybe this already exists? Or maybe this depends on Mocha? Or other existing packages?

Anyway, that is the concept. Thanks to the @nodedc for listening.

 PS One other feature, it should be able to run the same tests against a variety of environments: dev, qa, production, server01, server02, etc.

PSS. Since a RESTful API is like GETting a web page, it probably has broader uses than just APIs.

No comments: