Kiss My App

Friday, September 03, 2004

Test Driven Development

I last ranted on MVC frameworks on how they tie your business in. I also mentioned a little bit about unit testing. Developers talk about Test Driven development. What does that mean? Does that mean that I'm constantly running tests on everything I write? No, not really. Test Driven development is where the test environment drives your code/model.

Let me explain with a simple use case of logging a user in. The use case is conceptually simple, it's all in how you implement it. Some might dive into an MVC framework or start writing their Actions and JNDI or EJB dependencies and you will find yourself in a very complex situation very fast.

With Test Driven development, you are basically working in a 'main' method, which makes it difficult to commit or create dependencies on external technologies-- this is what we are trying to fight. By removing your ability to create external dependencies within a unit testing environment, the code you develop becomes much more portable.

Lets say we need to communicate to the Database for logging a user in. Some may commit to a persistence framework to take care of the dirty work, but the initial overhead on committing to something like Hibernate doesn't make your objects independently testable. You start getting into the practice of facades and delegates with seperate implementations/responsibilities.

I could get into code examples, but you get the idea. Just search the internet and you will find lots of examples of XP/Test Driven practices that are worth taking a second look at now that the hype has cleared.

0 Comments:

Post a Comment

<< Home