【问题标题】:Stop Phpunit execution during a TestSuite在 TestSuite 期间停止 Phpunit 执行
【发布时间】:2011-11-18 00:57:24
【问题描述】:

我使用一个类来执行一个带有 PhpUnit 的测试套件,例如:

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

开始单元测试:

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

如果“ClassOne”有错误或异常,测试继续“ClassTwo”。 如果第一次测试失败,我如何停止所有测试套件?

【问题讨论】:

    标签: php unit-testing phpunit


    【解决方案1】:

    适用于 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 配置套件”是解释选项。如果您可以在此时迁移,请记住这一点。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2018-07-03
        • 2023-04-01
        • 2018-08-17
        • 2020-09-09
        • 2018-10-31
        • 2023-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多