I once asked a team to question everything we do. We ended up with a few suggestions about things we could streamline but I was surprised at how quickly everyone on the team said “unit tests are good”.
Are unit tests good?
I’m strongly believe that unit tests are critical, but only if they offer a good return on investment. It takes a scary amount of time writing and maintaining a suite of unit tests, so any efficiency savings can really add up.
Why are you spending time and money writing and maintaining unit tests that are trivial?
Adam Tibi got me thinking about it a lot recently when I read his post on not testing MVC controllers.
When are unit tests “Bad”
I basically agree with Adam, but applied to every single line of code, not just controllers.
I’ve seen teams decide a certain % of code coverage is required and then just mechanically write test upon test until that magic number is hit. What’s the point of unit testing something like a simple wrapper that passes through to another layer. What have you achieved?
I find questioning the ROI of a unit test can also lead to some nice refactoring.
Question your return on investment of every unit test you write and maintain. Why are you spending time and money writing and maintaining unit tests that are trivial.
If the unit test is pointless, mark the code under test with some sort of “ExcludeFromCodeCoverage” attribute and spend your time, and money, on more important things.