SimpleTest PHP没有完成一个显示失败的测试程序


SimpleTest PHP not completing a testor showing a failure

由于某种原因,即使我在相同的环境中为其他类设置了一些其他类似的测试,SimpleTest也没有运行我的测试函数,但它并没有说测试是不可运行的。我得到的消息是(在绿色的成功条中):

FormControllerTest.php
0/1测试用例完成:0个通过,0个失败,0个异常。

所以它发现有一个测试用例,但它没有运行它,但它也没有抛出错误。

我已经将测试用例简化为最简单的,例如:
require_once(dirname(__FILE__) . '/simpletest/autorun.php');
require_once(dirname(__FILE__) . '/../FormController.php');
class FormControllerTest extends UnitTestCase {
    function shouldFail() {
        $this->assertFalse(true);
    }
}

我不明白为什么这不起作用。有没有人有任何建议,为什么它可能不会运行我的测试?

多谢

我找到了我的测试函数没有运行的原因。

根据SimpleTest网站的页面:

当自动运行器调用测试用例时,它将搜索其中以"test"名称开头的任何方法。

因此,当我将上述函数的名称更改为testShouldFail()时,它发现并正确地失败了测试。

希望对大家有所帮助。

尝试将require放到类的构造函数中。

class FormControllerTest extends UnitTestCase {
    function __construct() {
        require_once(dirname(__FILE__) . '/simpletest/autorun.php');
        require_once(dirname(__FILE__) . '/../FormController.php');
    }
    function shouldFail() {
        $this->assertFalse(true);
    }
}