News Feed
Sections




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

PHP Developer Blog:
Unit Tests How to test for Exceptions
April 20, 2009 @ 12:06:15

The PHP Developer Blog has a quick post for the unit testers out there on how to work with exception handling in your tests.

When unit testing, you'd also want to test whether your application throws Exceptions as expected (the following examples are based on SimpleTest). Assumption for the examples is, that we have a method that expects an integer as parameter.

Putting the assertion inside of the catch block won't work correctly since it wouldn't happen unless an exception is thrown. Instead he recommends putting it right after the exception try/catch and check to see if the exception variable is a type of 'Exception' (with another potential solution of adding in a check for an 'InvalidArgumentException').

0 comments voice your opinion now!
invalidargumentexception assert catch try exception unittest test


blog comments powered by Disqus

Similar Posts

DZone.com: Contributing to Paratest

PHP Developer Blog: Unit Tests: How to test for Exceptions

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 8)

International PHP Magazine: Poll Question: What Is the Best Way to Do QA for PHP?

Test.ical.ly Blog: Wrapping symfonys functional tests in a PHPUnit test case


Community Events





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


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

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