SimpleTest PHP 未完成显示失败的测试器

发布于 2024-12-02 18:26:02 字数 595 浏览 0 评论 0原文

由于某种原因,即使我设置了一些其他类似的测试并在同一环境中为其他类工作,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);
    }

}

我无法理解为什么这不起作用。有人对为什么它可能不运行我的测试有任何建议吗?

非常感谢

For some reason, even I have some other similar tests set up and working for other classes in the same environment, SimpleTest isn't running my test function, but it's not saying that the tests are unrunnable. The message I get is (in a green success strip):

FormControllerTest.php
0/1 test cases complete: 0 passes, 0 fails and 0 exceptions.

So it has found that there is one test case, but it's not run it, but it's also not throwing an error.

I've reduced the test case to the simplest possible like:

require_once(dirname(__FILE__) . '/simpletest/autorun.php');
require_once(dirname(__FILE__) . '/../FormController.php');
class FormControllerTest extends UnitTestCase {

    function shouldFail() {
        $this->assertFalse(true);
    }

}

I can't understand why this is not working. Does anyone have any suggestions as to why it might not be running my test?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昨迟人 2024-12-09 18:26:02

我找到了我的测试功能未运行的原因。

根据 SimpleTest 网站的此页面

当自动运行程序调用测试用例时,它将搜索以名称“test”开头的任何方法。

因此,一旦我将上述函数的名称更改为 testShouldFail(),它就会发现并正确地使测试失败。

希望对某人有帮助。

I found the reason that my test function wasn't running.

According to this page from the SimpleTest website:

When the test case is invoked by the autorunner it will search for any method within that starts with the name "test".

so, as soon as I changed the name of my above function to testShouldFail() it found and correctly failed the test.

Hope that helps somebody.

猫性小仙女 2024-12-09 18:26:02

尝试将需求放入类构造函数中。

class FormControllerTest extends UnitTestCase {

    function __construct() {
        require_once(dirname(__FILE__) . '/simpletest/autorun.php');
        require_once(dirname(__FILE__) . '/../FormController.php');
    }

    function shouldFail() {
        $this->assertFalse(true);
    }

}

Try to put the requires inside a class constructor.

class FormControllerTest extends UnitTestCase {

    function __construct() {
        require_once(dirname(__FILE__) . '/simpletest/autorun.php');
        require_once(dirname(__FILE__) . '/../FormController.php');
    }

    function shouldFail() {
        $this->assertFalse(true);
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文