Earlier I promised to elaborate on why slow unit tests are a sign of problems (or a smell if you like). So here it goes.
The first thing I would like to look at is when the complete test suite takes too long to run to be part of a tight TDD-loop. If it is just the number of tests that makes the difference and each single test is super fast you will have a very large number of tests. Probably several thousands of tests. This can only mean two things. The least bad thing is that you have a very large application that really need all these tests. But you could probably split things up into different modules and test each module by it self thus reducing the number of tests that need to be run when you’re working on a single module. Any dependencies between the modules can be faked in your day to day work. A much worse problem is that you’re over-testing your code. That means testing the same thing in several similar (but not identical) ways. While over-testing it self should not be a problem it impacts TDD bad in two ways. First of all writing more tests takes more time so you get the feel that TDD is much slower than “developing the old way”. It also makes the feedback slower since tests takes longer to run and that means to loose focus.
The second reason for slow tests is when a single test actually takes to long to execute just by itself. This is a sign of trouble since it probably means you’re having badly written tests or even worse; badly designed production code. The reason for the test to be slow is typically because it takes some time to set up the circumstances for the test. The reason for this is typically a bad design since it is difficult or impossible to fake/stub/mock dependencies away in your test code. If you’re having trouble faking dependencies you probably have a too tightly coupled design which most people I know tend to think is a bad design.
So whenever you feel the complete test suite takes too long to run, don’t start looking at what is wrong with the tests – start looking at what is wrong with your production code…