If setUpBeforeClass() fails, test failures are hidden in PHPUnit's JUnit XML output

Posted by Adam Monsen on Stack Overflow See other posts from Stack Overflow or by Adam Monsen
Published on 2012-06-06T22:36:14Z Indexed on 2012/06/06 22:40 UTC
Read the original article Hit count: 242

Filed under:
|

If setUpBeforeClass() throws an exception, no failures or errors are reported in the PHPUnit's JUnit XML output. Why?

Example test class:

<?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');
  }
}

Command line:

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

Console output:

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 output:

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

More info:

$ 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

© Stack Overflow or respective owner

Related posts about php

Related posts about phpunit