Unit Testing – How do you do it?

I’ve been reading about some of the tenets of Xtreme Programming (XP) and in particular the use of Unit Testing. At work I sent out the following article:

Strong Typing vs. Strong Testing

Very interesting, but in real life I find there is a huge divide between theory and practice. So here is a question to any of you out there. How do you do it?

The problem I’m having is that the tests I see as examples are not valid in real world environments. For example, if you are designing UI and you have a simple Dialog, you need a UI automator package to test that dialog. If you are building a web app, you will need a test database and fake-browser to exercise the UI. How do you tests without having to write a system that sets up a database and verifies its consistency (lots of work and the tests are time consuming)? How do you verify that the text in a field looks correct?

One thing that I find helpful is to separate the UI, if possible from the implementation. So, for example, in the dialog case above… I would never let the Dialog touch the database. I would have it use data passed in or an in-memory model. The same for web pages. I would use a templating system there. This should help with Unit Testing, but the thorny issues I mention above still stand.

So… what do you use and how do you do it?

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published.