News Feed
Sections




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

Phil Bennett:
Dependency Injection as a Tool for Testing
August 16, 2013 @ 10:29:42

Phil Bennett has a new post today talking about a way that you could use dependency injection in your testing, making it easier to work your system by using stubs, fakes and mocks.

Dependency injection is a simple design pattern that provides several benefits, one of which is the ability to vastly improve your unit test suite. In this post I am going to be looking at how this is done and how it relates to certain testing methodologies.

He talks some about the refactoring of an application to allow for easier dependency injection and how, while easier, can still make it difficult to abstract out things like database functionality. Instead, he suggests creating "fake" classes that model the behavior of the needed dependency. He shows examples of each type - a fake, stub and mock - and talks some about the differences between each (and situations one might be used over the other).

0 comments voice your opinion now!
dependency injection unittest stub mock fake

Link: http://happyaccidents.me/dependency-injection-as-a-tool-for-testing

blog comments powered by Disqus

Similar Posts

Srdjan Vranac's Blog: Custom Repository with DIC in Symfony2

Chris Jones: DTracing a PHPUnit Test: Looking at Functional Programming

Greg Beaver's Blog: Be careful of PEAR 1.4.4 and older installs when uninstalling a package

Brandon Savage's Blog: Interfaces Make Testing Easier

Fabien Potencier's Blog: On PHP 5.3, Lambda Functions, and Closures


Community Events

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


symfony2 laravel conference framework version podcast series community introduction php7 release opinion api interview voicesoftheelephpant library install performance example extension

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