News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthias Noback:
A better PHP testing experience Part II Pick your test doubles wisely
July 10, 2014 @ 09:36:27

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.

0 comments voice your opinion now!
testdouble mock unittest phpunit pick wisely

Link: http://php-and-symfony.matthiasnoback.nl/2014/07/test-doubles/

blog comments powered by Disqus

Similar Posts

Brandon Savage's Blog: Peer Review: Testable Code And Architecture

Till Klampaeckel's Blog: Selenium vs. Saucelenium

VG Tech Blog: Mocking the File System Using PHPUnit and vfsStream

Sebastian Bergmann\'s Blog: PHPUnit 3.0

Sebastian Bergmann's Blog: So Long, and Thanks for all the PEARs


Community Events





Don't see your event here?
Let us know!


framework update introduction package tool laravel opinion podcast version language series application interview community voicesoftheelephpant composer symfony library release security

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework