Home >Backend Development >PHP Tutorial >[PHP]PHPUnit入门之三
Testing Exceptions
@expectedException声明用来测试测试代码中指定异常是否被抛出
代码
1 php
2 require_once ' PHPUnit/Framework.php ' ;
3
4 class ExceptionTest extends PHPUnit_Framework_TestCase
5 {
6 /* *
7 * @expectedException InvalidArgumentException
8 */
9 public function testException()
10 {
11 }
12 }
13 ?>
代码
1 php
2 require_once ' PHPUnit/Framework.php ' ;
3
4 class ExceptionTest extends PHPUnit_Framework_TestCase
5 {
6 public function testException()
7 {
8 $this -> setExpectedException( ' InvalidArgumentException ' );
9 }
10 }
11 ?>
代码
1 php
2 class ExpectedErrorTest extends PHPUnit_Framework_TestCase
3 {
4 /* *
5 * @expectedException PHPUnit_Framework_Error
6 */
7 public function testFailingInclude()
8 {
9 include ' not_existing_file.php ' ;
10 }
11 }
12 ?>