在TestSuite期间停止Phpunit执行

Kev*_*ion 4 php phpunit unit-testing

我用一个类用PhpUnit执行一个测试套件,如:

$suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework');
$suite->addTestSuite('ClassOne');
$suite->addTestSuite('ClassTwo');
return $suite;
Run Code Online (Sandbox Code Playgroud)

要开始单元测试:

# phpunit --stop-on-failure TestSuite.php
Run Code Online (Sandbox Code Playgroud)

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

edo*_*ian 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.
Run Code Online (Sandbox Code Playgroud)

并且一个失败了 --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.
Run Code Online (Sandbox Code Playgroud)

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

作为侧节点.如果你看一下documentation of the current version唯一的"按文件系统套件"和"由xml配置套件"的解释选项.如果您可以在此时迁移,请记住这一点.