Question

I'd like to integrate PHPUnit to my framework. By this, I mean that I have to do some initializing in the beginning, like setting up autoloads, before I'd run the tests.

I'd like to use the cli test runner, and if I understand correctly, I have to make a class, that has a static function suite(), which returns an instance of PHPUnit_Framework_TestSuite, and add tests to this suite, as noted on http://www.phpunit.de/manual/current/en/textui.html.

So far I have come up with:

class MyTestFW {
    public static function suite() {
        // Do framework initialization here

        $suite = new PHPUnit_Framework_TestSuite();
        $suite->addTest(new SimpleTest());

        // Add more tests

        return $suite;
    }
}

SimpleTest is a very basic test class, that extends PHPUnit_Framework_TestCase. When I run "phpunit MyTestFW", I always get:

PHPUnit 3.3.16 by Sebastian Bergmann.

E

Time: 0 seconds

There was 1 error:

1) (SimpleTest)
RuntimeException: PHPUnit_Framework_TestCase::$name must not be NULL.

Could someone help me out a little please?

Was it helpful?

Solution

PHPUnit_Framework_TestCase::$name gets set in the TestCase constructor, so you could try this:

$suite->addTest(new SimpleTest('simpletest'));

edit1:

I don't know your code, so i don't know if this helps.
What I usually see is this (as a replacement of the above, not addition):

$suite->addTestSuite('SimpleTest');

edit2:

phpunit documentation: Chapter 7 - Organizing Tests

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