如果setUpBeforeClass()失败,则测试失败隐藏在PHPUnit的JUnit XML输出中

时间:2012-06-06 22:36:14

标签: php phpunit

如果setUpBeforeClass()抛出异常,则PHPUnit的JUnit XML输出中不会报告任何失败或错误。为什么呢?

示例测试类:

<?php

class Test extends PHPUnit_Framework_TestCase
{
  public static function setUpBeforeClass() {
    throw new \Exception('masks all failures in xml output');
  }

  public function testFoo() {
    $this->fail('failing');
  }
}

命令行:

phpunit --verbose --log-junit out.xml Test.php

控制台输出:

PHPUnit 3.6.10 by Sebastian Bergmann.

E

Time: 0 seconds, Memory: 3.25Mb

There was 1 error:

1) Test
Exception: masks all failures in xml output

/tmp/pu/Test.php:6

FAILURES!
Tests: 0, Assertions: 0, Errors: 1.

JUnit XML输出:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="Test" file="/tmp/phpunit-broken/Test.php"/>
</testsuites>

更多信息:

$ php --version
PHP 5.3.10-1ubuntu3.1 with Suhosin-Patch (cli) (built: May  4 2012 02:21:57) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

可能相关:

0 个答案:

没有答案