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

Benjamin Eberlei's Blog: Using Zend_Soap Server and Autodiscover in a Controller

Test.ical.ly Blog: Best practice of PHPUnit testing a symfony 1.4 plugin

Content with Style Blog: Unit testing controllers with Zend Framework

PHPied.com: JSON renderer for Text_Highlight

Daniel Hofstetter's Blog: How to update multiple divs with Ajax


Community Events





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


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

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