dsjpqpdm620596 2014-09-03 20:44
浏览 37

Unittests在父类中运行两次

For many good reasons I put some tests into parent test class und some tests in inhereted class. I have got this structure then:

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

This command I use to start phpunit: phpunit --configuration unit.xml I tried this one too, but with same result: phpunit --configuration unit.xml --testsuite foo

So now I want to run all tests in a folder foo. Problem is, that tests in bar.php will be running twice and I have no idea why. Do someone has the answer to that? Is it maybe a feature of phpunit? How can I told phpunit not to run them twice?

If I run phpunit bar/foo/foo.php everything works fine and test function in bar.php is running only once.

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 responce

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>
  • 写回答

1条回答 默认 最新

  • drvvepadi289421028 2015-12-20 23:11
    关注

    If you don't intend to execute the parent test class on its own, make it abstract, this prevents PHPUnit from trying to instantiate it and running its tests.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害