News Feed
Sections




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

Master Zend Framework:
Simplifying Unit Testing (and asking for help when needed)
March 20, 2014 @ 11:54:16

On Matthew Ssetter's "Master Zend Framework" blog today he talks about simplifying unit testing and some of his experience with getting too complicated in his own testing practices.

Recently I was a bit stuck, trying to figure out how to test a section of an application I've been developing. Specifically, I was trying to mock a HydratingResultSet in a controller test, so it could be the return value of a method call on a datasource, my controller needed. I was sure it was the right approach to help ensure the functionality in question was working properly. But no matter what I tried, my tests didn't work, because I wasn't mocking it correctly. [...] I asked for help [on IRC], laying out the problem as I saw it. The first response which came back, from Ocramius, stopped me dead in my tracks: "Why are you trying to do that?"

He includes a bit of background on what he was trying to test and the functionality around it and how, when he stopped to think about it, wondered why he was testing it too. He talks about the refactor he made to his code with a positive end result - the tests now passed. He suggests a few questions to ask yourself when writing your tests such as "am I doing too much?" or "am I testing code in the right place?" Chances are, if you step back and really look at what you're testing, you might realize that the answer to these questions is just to simplify.

He finishes the post with a few suggestions, some of his own personal favorites, of places you can go for help when questions do pop up. He points out that the usual excuses shouldn't be a blocker on asking for help. He is "encouraging you to set your pride, ego and excuses aside and when you're stuck: ask for help."

0 comments voice your opinion now!
testing simplify unittest zftalk help question

Link: http://www.masterzendframework.com/people/right-approach-unit-testing-asking-help

blog comments powered by Disqus

Similar Posts

Padraic Brady's Blog: Mutation Testing Brain Dump

Matthias Noback: The PHP testing experience: Interview by Fernando Arconada

Sebastian Bergmann's Blog: Sharing Fixtures and Stubbing/Mocking Static Methods

Symfony Blog: The wait is over: symfony 1.1 released

QaFoo.com: Code Reuse By Inheritance


Community Events





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


series conference list code application community release laravel development language tips zendserver threedevsandamaybe introduction deployment interview api podcast developer framework

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