3 ms·
While I agree with other commenters that "Testing is like eating" and "No Silver Bullet", I think there is value in explicitly naming and discussing what happen
by RossBencina 8y ago
While I agree with other commenters that "Testing is like eating" and "No Silver Bullet", I think there is value in explicitly naming and discussing what happens when unit testing goes wrong. The linked article raises some good points about testing antipatterns.
Although there isn't a strict trade-off between code simplicity and testability, I have personally found that focusing on unit testing can take my focus away from thinking about simplicity an correctness-by-design. Sometimes I have to recalibrate: simplicity and correctness-by-design should be considered during the "refactor" phase of red-green-refactor.
The article could do more to emphasise that both TDD and BDD are "test first" methods. They are ways to develop code by first specifying what the code should do by writing tests. Working this way you often end up with different kinds of tests (and maybe even more testable code?) than if you just apply a post-hoc "write unit tests for everything" approach. Roy Osherove often mentions this in his test reviews.[0]
The article questions whether integration tests should be preferred over unit tests, claiming that unit tests don't verify that the program performs it's main task correctly. This raises the question of how to allocate resources to testing, and being clear on what your goals are for testing. This reminds me of the "Test Pyramid".[1]
It seems to me that it's a good idea to have integration tests that verify that the program satisfies its use cases. But if you want assurance that each component of the code does what it claims it does, then you want unit tests. The middle ground is what J.B. Rainsberger has called 'integrated tests' -- tests that simultaneously test aggregates of multiple units.[2] J.B. argues that you're better off with unit tests, since achieving good test coverage with 'integrated tests' entails combinatorial explosion.
[0] http://artofunittesting.com/ http://artofunittesting.com/ (see Test Reviews in the right sidebar)
[1] https://martinfowler.com/bliki/TestPyramid.html https://martinfowler.com/bliki/TestPyramid.html
[2] J.B. Rainsberger - Integrated Tests Are A Scam https://vimeo.com/80533536 https://vimeo.com/80533536