简体   繁体   English

没有断言phpunit但有

[英]no assertions phpunit but there is

I have a testcase for phpunit, but when it runs its reports there are no assertions. 我有一个用于phpunit的测试用例,但是当它运行其报告时没有断言。 There are clearly assertions. 显然有断言。 it looks no different to my other files. 它看起来与我的其他文件没有什么不同。 the number of tests reported is accurate if i add an remove tests but the assertions aren't running. 如果我添加删除测试但断言未运行,则报告的测试数量是准确的。 whats the deal. 这是怎么回事。

class DeferTest extends PHPUnit_Framework_Testcase     
{
    public function testNotRequiredNumberOfArgs()
    {
        $this->setExpectedException('DeferException');
        $defer = null;
        $defer = new Defer();
    }


    public function testRun()
    {
        $defer = new Defer($this, 'runTest', 1, 2, 3);
        $this->assertEquals($defer->run(4, 5, 6), array(1, 2, 3, 4, 5, 6));
    }

    public function testClassNameRun()
    {
        $defer = new Defer('TestClass', 'run', 1, 2, 3);
        $this->assertEquals($defer->run(4, 5, 6), array(1, 2, 3, 4, 5, 6));
    }

    public function runTest()
    {
        return func_get_args();

    }
}

Console output 控制台输出

$ phpunit test/core/DeferTest.php
PHPUnit 3.7.21 by Sebastian Bergmann.
... 
Time: 0 seconds, Memory: 5.50Mb 
OK (3 tests, 0 assertions)

Thanks to cyprian I found by asserting true in each case and commenting out the runTest method that the problem was the runTest method. 多亏了塞浦路斯人,我通过在每种情况下都声明true并注释掉runTest方法来发现问题出在runTest方法上。 It seems I was overriding a method from phpunit test case. 看来我在phpunit测试用例中重写了一种方法。 Renaming the method fixed the problem. 重命名方法可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM