News Feed
Jobs Feed
Sections




News Archive
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

Jani Hartikainen's Blog: Handling errors in Zend Framework

Community News: TestFest 2008 Announcement

Tony Freixas's Blog: High-performance debugging

Anna Filina's Blog: 10 Reasons to Write Unit Tests

NetTuts.com: Testing Like a Boss in Laravel: Models


Community Events











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


zendframework2 example language introduction testing unittest release podcast code functional interview series application community object development opinion framework phpunit conference

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