在 TestSuite 期间停止 Phpunit 执行

发布于 2024-12-04 16:01:40 字数 369 浏览 0 评论 0原文

我使用一个类来使用 PhpUnit 执行测试套件,如下所示:

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

启动单元测试:

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高速公鹿 2024-12-11 16:01:40

适用于 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;
    }
}

作为侧节点运行失败。如果您查看当前版本的文档 只有“suites by file system”和“suites by xml config”是解释选项。如果您可以在此时迁移,请记住这一点。

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.

数理化全能战士 2024-12-11 16:01:40

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文