Unittests在父类中运行两次

时间:2014-09-03 20:44:39

标签: php unit-testing phpunit automated-tests

出于很多好的理由,我将一些测试放入了父测试类中,并将一些测试放在了固有类中。我有这个结构:

/bar/foo/foo.php
/bar.php

我用这个命令启动phpunit:phpunit --configuration unit.xml我也尝试了这个,但结果相同:phpunit --configuration unit.xml --testsuite foo

所以现在我想在文件夹foo中运行所有测试。问题是,bar.php中的测试将运行两次,我不知道为什么。有人有答案吗?它可能是phpunit的一个功能吗?我怎么能告诉phpunit不要运行它们两次?

如果我运行phpunit bar/foo/foo.php一切正常,bar.php中的测试功能只运行一次。

foo.php

require_once '/bar.php';

class foo_test extends bar_test {

    public function test_1_pass() {
        $this->assertEquals('a', 'a');
    }

}

bar.php

class bar_test extends PHPUnit_Framework_TestCase {

    public function test_2_fail() {
        $this->assertEquals('a', 'b');           
    }

}

Unittest响应

PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from /unit.xml

F.F

Time: 104 ms, Memory: 3.25Mb

There were 2 failures:

1) bar_test::test_2_fail
Failed asserting that two strings are equal.

/bar.php:6

2) foo_test::test_2_fail
Failed asserting that two strings are equal.

/bar.php:6

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

unit.xml

<phpunit 
    backupGlobals="false" 
    backupStaticAttributes="false" 
    syntaxCheck="false">
  <testsuites>
    <testsuite name="foo">
      <directory suffix=".php">bar/foo</directory>
    </testsuite>
  </testsuites>
</phpunit>

0 个答案:

没有答案