2 ms·
I finally have words to describe why I prefer behavior testing over strict definitions of unit tests. The use case of mocks/stubs/etc for me is “this thing is
by eyelidlessness 6y ago
I finally have words to describe why I prefer behavior testing over strict definitions of unit tests.
The use case of mocks/stubs/etc for me is “this thing is expensive to execute or external and can’t be validated directly”. In the former case, validating the inputs to the expensive interface is buttressed by thorough and verifiable testing of the thing it calls into. In the latter case, you provide an interface that behaves according to your understanding of the external service without requiring its availability.
In pure unit testing, the “external” boundary is hungry and consumes as much interaction between code components as possible. In behavior testing, you extend end user validation as far as is practical or possible.
The benefit of that is you can verifiably satisfy user needs up to the limits of your testing/testing environment, in user language. Wherever you need to silo who the “user” is (eg service/api boundaries), you can do so. But your tests are designed to validate user assumptions first, and fussy technical details after.
- hakre 6y agoSo if the test is red, it verifies that the users assumptions were wrong first, right? ;)