在TestSuite期间停止Phpunit执行

时间:2011-09-15 16:10:02

标签: php unit-testing phpunit

我使用类来使用PhpUnit执行测试套件,如:

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

开始单元测试:

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

如果“ClassOne”有错误或异常,则测试继续“ClassTwo”。 如果第一次测试失败,我怎么能阻止所有的测试?

2 个答案:

答案 0 :(得分:5)

适用于PHPUnit 3.5.14

使用输出下方的代码符合预期:

两个正常运行失败:

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.

,其中一个使用--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;
    }
}

作为副节点。如果您只查看documentation of the current version仅按“文件系统套件”和“按xml配置套件”解释选项。如果您可以在此时迁移,请记住这一点。

答案 1 :(得分:0)

听起来像phpunit中的一个错误。将phpunit升级到最新版本。如果这没有帮助,请打开错误报告。