News Feed
Sections




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

James Fuller:
Use @dataProvider to reduce duplication and improve the maintainability of your tests
January 31, 2014 @ 12:50:39

Code duplication is a common problem for developers. It's easy to copy and paste code around your application, but you're asking for trouble. Unfortunately, this kind of problem also extends to unit tests. In this new post to his site James Fuller looks at one way to help with this - using the @dataProvider to limit the repetitive data sets across tests.

PHPUnit offers a handy annotation called @dataProvider which can be used for all sorts of handy testing situations. Typically you will use this to feed in a wide variety of data into the same test to ensure that the system-under-test can handle a variety of inputs. Over time I have discovered a few other neat uses for dataProvider methods that I want to share with you today.

He provides some code samples showing how to use the dataProvider in a few tests, setting up an "allowed word" example. He gets a bit more complex with another test that takes in multiple parameters to "mix colors". In his last example he shows a data provider that converts names from camelCase to user_scores.

0 comments voice your opinion now!
unittest dataprovider duplication dataset tutorial

Link: http://www.jblotus.com/2014/01/29/use-dataprovider-to-reduce-duplication-and-improve-the-maintainability-of-your-tests/

blog comments powered by Disqus

Similar Posts

Dave Dash's Blog: Finding things using Zend Search Lucene in symfony

Fernando Bassani's Blog: Putting the PHP/Java Bridge to work - I

Zend Developer Zone: Debugging PHP applications with xdebug

DevShed: Positioning Strings with the show_xy() Method in PDF Documents with PHP 5

Felix Geisendorfer's Blog: Setting up Xdebug on Mac OS X (or Win32 / Linux)


Community Events

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


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

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