4

I use a class to execute a testsuite with PhpUnit like :

$suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework');
$suite->addTestSuite('ClassOne');
$suite->addTestSuite('ClassTwo');
return $suite;

To start the unit test :

# phpunit --stop-on-failure TestSuite.php

If "ClassOne" has an error or exception, the test continue with "ClassTwo". How I could stop all the testsuites if the first test failed?

2 Answers 2

5

Works with PHPUnit 3.5.14

Using the code below the outputs are as expected:

Two fails running it normally:

phpunit AllTests.php 
PHPUnit 3.5.14 by Sebastian Bergmann.

FF

Time: 0 seconds, Memory: 6.25Mb

There were 2 failures:

1) Framework_AssertTest::testFails
Failed asserting that <boolean:true> matches expected <boolean:false>.

/home/edo/test/AllTests.php:7

2) Other_AssertTest::testFails
Failed asserting that <boolean:true> matches expected <boolean:false>.

/home/edo/test/AllTests.php:13

FAILURES!
Tests: 2, Assertions: 2, Failures: 2.

and one fail running it with --stop-on-failure

phpunit --stop-on-failure AllTests.php 
PHPUnit 3.5.14 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 6.25Mb

There was 1 failure:

1) Framework_AssertTest::testFails
Failed asserting that <boolean:true> matches expected <boolean:false>.

/home/edo/test/AllTests.php:7

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

AllTests.php

<?php


class Framework_AssertTest extends PHPUnit_Framework_TestCase {

    public function testFails() {
        $this->assertSame(false, true);
    }
}

class Other_AssertTest extends PHPUnit_Framework_TestCase {
    public function testFails() {
        $this->assertSame(false, true);
    }

}

class Framework_AllTests
{
    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework');

        $suite->addTestSuite('Framework_AssertTest');
        $suite->addTestSuite('Other_AssertTest');

        return $suite;
    }
}

class Other_AllTests
{
    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework');

        $suite->addTestSuite('Other_AssertTest');

        return $suite;
    }
}

class AllTests
{
    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('PHPUnit');

        $suite->addTest(Framework_AllTests::suite());

        return $suite;
    }
}

As a side node. If you look at the documentation of the current version only "suites by file system" and "suites by xml config" are explained options. Just to keep that in mind if you can migrate at the point.

0

Sounds like a bug in phpunit. Upgrade phpunit to the latest version. If that does not help, open a bug report.

Not the answer you're looking for? Browse other questions tagged or ask your own question.