Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top