Matthias Noback has posted the second part in his look at a better PHP testing experience, focusing this time on picking test doubles wisely. Test doubles are a more general term for what most developers who test code might call a "mock".
In the introduction to this series I mentioned that testing object interactions can be really hard. Most unit testing tutorials cover this subject by introducing the PHPUnit mocking sub-framework. The word "mock" in the context of PHPUnit is given the meaning of the general concept of a "test double". In reality, a mock is a very particular kind of test double. [...] Each type of test double has its own merits and it is vital to the quality of your test suite that you know when to use which one.
He builds on the "non-assertion centric" approach he talked about in the first part and how a similar problem could be caused by the large amount of work needed to create complex mocks. He points out that having to create them in a specific way and the mocks being a bit difficult to use can make the tests fragile and easily broken. He looks at a few different kinds of test doubles (mocks, dummies, spies) with code examples for each for added clarification. He also makes two recommendations for testing instead of complex mocking: create the actual mock classes instead of just mocks and don't overuse mocking.
Link: http://php-and-symfony.matthiasnoback.nl/2014/07/test-doubles/
没有评论:
发表评论