News Feed
Sections




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

Padraic Brady's Blog:
Unit Testing Multiple Assertions And Lazy/Shallow Testing Are Evil
February 13, 2009 @ 09:31:33

In a new post today Padraic Brady takes a look at unit testing and two of the bad practices that can develop over time when writing your tests - overloading tests with assertions and lazy/shallow tests.

In short, every test you write requires that you setup the test environment, create a scenario for possible failure, add an assertion, and then ensure the source code makes that assertion pass. This requires code - sometimes a lot of code. So adding multiple assertions to each test minimizes the work needed to write tests, since using multiple assertions takes advantage of existing code to avoid writing new stuff to clutter your test classes. It can also help to tackle multiple but related results in the same test.

He gives brief examples of both instances and some of the problems associated with them. Multiple assertions, while nice for fine tuning the results of the testing, can also confuse since, if one assertion fails, the whole test fails too. The other end of the spectrum is a problem too - writing tests that don't do enough to really check the information passed in. These shallow tests can lead to issues down the line if unanticipated data might come along.

Really, its all about finding that "sweet spot" in developing tests - not too much, not too little - and keeping it simple while not missing out on assertions that need to be made.

0 comments voice your opinion now!
unittest phpunit lazy shallow multiple assertion example


blog comments powered by Disqus

Similar Posts

Scarletlullaby.com: Refactoring to Rails (MVC) in PHP

DZone.com: PHPUnit_Selenium

DeveloperTutorials.com: Upload Files to MySQL using PHP Tutorial

Mike Potter's Blog: Flex and PHP Samples from Adobe MAX Europe

PHPMaster.com: Continuous Integration (with Jenkins), Part 2


Community Events





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


podcast list release wordpress series configure testing opinion introduction framework threedevsandamaybe language install unittest refactor developer code interview laravel community

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