本文介绍了PHPUnit什么也没做,没有输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一些测试用例,并希望通过PHPUnit进行尝试.但是,它不起作用.如果我运行phpunit CategoryTest,它将输出:

I have written some test cases and want to try them out with PHPUnit. However, it does not work.If I run phpunit CategoryTest it outputs:

PHPUnit 3.7.14 by Sebastian Bergmann.

如果执行phpunit --log-json error.log CategoryTest,则会显示error.log文件:

If I do phpunit --log-json error.log CategoryTest, error.log file displays:

{"event":"suiteStart","suite":"CategoryTest","tests":5}
{"event":"testStart","suite":"CategoryTest","test":"CategoryTest::test__construct"}

因此,它发现文件中有5个测试,开始执行第一个测试,并且无故停止.有什么日志可以找到我为什么不继续执行的原因吗?另外,如果我对其他文件(例如phpunit --log-json error.log UserTest)运行测试,则外壳程序将不显示任何输出,并且error.log文件也不显示.

So, it finds that there are 5 tests in the file, starts doing the first one and for no reason stops. Is there any log where I could find a reason why it would not continue execution?Also, if I run test on some other file, say phpunit --log-json error.log UserTest, the shell does not display any output and neither does error.log file.

我尝试重新安装它,如在其他类似问题之一中所建议的那样,但它没有执行任何操作.

I tried reinstalling it, as it was suggested in one of the other similar questions, but it didn't do anything.

有什么想法我可以解决吗?

Any ideas how I could fix it?

require_once '../Category.class.php';
require_once '../../db_connect.php';
require_once 'PHPUnit/Framework/TestCase.php';

class CategoryTest extends PHPUnit_Framework_TestCase {

private $Category;

protected function setUp() {

    parent::setUp ();
    $this->Category = new Category(0, $mdb2);

}

protected function tearDown() {
    $this->Category = null;
    parent::tearDown ();
}

public function __construct() {

}

public function test__construct() {

    $this->markTestIncomplete ( "__construct test not implemented" );

    $cat = $this->Category->__construct(0, $mdb2);

    $this->assertInstanceOf('Category', $cat);
}

public function testReturnID() {

    $this->markTestIncomplete ( "returnID test not implemented" );

    $id = $this->Category->returnID();

    $this->assertEquals(0, $id);

}
  ...
}

变量$mdb2来自db_connect.php文件.

Variable $mdb2 comes from the db_connect.php file.

我知道了.问题是我在类之外包含了一个变量.

推荐答案

您不应覆盖TestCase中的__construct()方法.构造函数为测试设置了模拟生成器和其他一些必需的东西,因此,如果覆盖构造函数,则会出现很多奇怪的行为和不良的副作用. setUp()方法是用于初始化测试的特殊方法.

You shouldn't overwrite the __construct() method in your TestCase. The constructor sets up the mock generator and some other mandatory thing for the test, so you get a lot of strange behaviour and unwanted side effects if you overwrite the constructor. The setUp() method is the special method you should use to initialize your test.

这篇关于PHPUnit什么也没做,没有输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:01