开发者

SimpleTest PHP not completing a testor showing a failure

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


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.


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);
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜