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

Sebastian Bergmann's Blog: PHPUnit 3.0 Beta 3

Matthew Turland's Blog: Process Isolation in PHPUnit

Sebastian Bergmann's Blog: Using PHPUnit from a Git Checkout

Dave Marshall: Probing Test Suite Quality with Mutation Testing

Padraic Brady's Blog: The PHPSpec Zend Framework App Testing Manifesto: Preamble


Community Events

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


interview series opinion community application release library configure laravel symfony2 composer example conference podcast introduction voicesoftheelephpant api php7 framework performance

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