Why are unit tests too complicated?
One thing that often strikes me is that unit test cases often are too complicated. I think there are many different reasons for this and because the reasons vary one need to take different approached in dealing with them.
1. Too smart developers
Developers in general like to do complicated things, this rubbs off on the unit tests. Instead of keeping them small en easy one introduces too many abstractions and other clever solutions.
How do we deal with that? Increase communication. Let the developers explain the test cases for people that aren't generally involved in development.
2. The design sucks
If the design is poor and complex this will affect the unit tests, and make them smelly. How do we know that this is the case? Let someone new start working with the system and if he or she is slow in being up to speed, there is a possiblity that the design is to complex. One other thing it to run some kind of metric software on the code and make sure that it is not to complex.
3. The unit tests are not unit tests
The unit tests are not unit tests. Ok then so what is a unit test? The unit test aims test the smallest part of the application, eg addition of two numbers (nice school book example ;) ). An example of a test that isn't a unit test is "Log in, place an order verify order in order book." Refactor your tests and separate funcional tests (which of course can be implemented in code) from unit tests.
Labels: complicated, design, refactor, test, Unit test
