Every year, a new generation of developers start their career. And every year, I see these new developers struggling with writing tests. And if you dare to go one step further, and introduce them to Test Driven Development, they get even more confused.
Don't misunderstand me, they are quite fast in understanding the mechanics of the testing frameworks(MsTest, Xunit, ...). But it turns out that is really hard to write good, maintainable tests that help to move forward instead of becoming a bottleneck.
One of the reasons this is such a problem, is that what is now described as Test Driven Development is not aligned with the original intention. Ian Cooper has a great talk exactly about this issue:
Ian Cooper reminds what was Kent's original proposition on TDD, what misunderstandings occurred along the way and suggests a better approach to TDD, one that supports development rather impeding it.
There are 2 key elements of his talk, that I think are most important:
- It is all about ‘behaviours’. We want to validate the outside observable behaviours of our system, not the internal implementation details.
- The ‘unit of isolation’ is not the class we want to test, it is the test itself. A consequence of seeing the class itself as the unit of isolation is that an extensive amount of mocking and stubbing becomes necessary.
A must see even before you have written your first unit test…