Php 在父类中运行两次的单元测试

Php 在父类中运行两次的单元测试,php,unit-testing,phpunit,automated-tests,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的

出于许多好的原因,我将一些测试放在父测试类中,而将一些测试放在固有类中。我得到了这个结构:

/bar/foo/foo.php

/bar.php

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

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

如果我运行
phpunitbar/foo/foo.php
一切正常,
bar.php
中的测试函数只运行一次

foo.php

bar.php

单元测试响应

unit.xml


酒吧/餐厅

如果您不打算单独执行父测试类,请将其抽象化,这将阻止PHPUnit尝试实例化它并运行它的测试。

您使用什么命令来启动PHPUnit?已将该命令添加到description@gontrollez如果您仅使用/bar/foo/foo.php测试更改文件节点的目录XML节点会发生什么情况?我将目录行替换为
bar/foo/foo.php
,但我也有同样的行为,我解决了问题。这是班级命名,这是错误的。如果它与文件名相同,则一切正常。
require_once '/bar.php';

class foo_test extends bar_test {

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

}
class bar_test extends PHPUnit_Framework_TestCase {

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

}
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.
<phpunit 
    backupGlobals="false" 
    backupStaticAttributes="false" 
    syntaxCheck="false">
  <testsuites>
    <testsuite name="foo">
      <directory suffix=".php">bar/foo</directory>
    </testsuite>
  </testsuites>
</phpunit>