Adds the tests from the given class to the suite.
public addTestSuite ( mixed $testClass ) | ||
$testClass | mixed |
class MyTestSuite extends PHPUnit_Framework_TestSuite { public static function suite() { $suite = new self(); $suite->addTestSuite('MyTestCase1'); $suite->addTestSuite('MyTestCase2'); return $suite; } } class MyTestCase1 extends PHPUnit_Framework_TestCase { public function testSomething() { $this->assertTrue(true); } } class MyTestCase2 extends PHPUnit_Framework_TestCase { public function testSomethingElse() { $this->assertEquals(1, 1); } } // Run the test suite PHPUnit_TextUI_TestRunner::run(MyTestSuite::suite());
class MyTestListener implements PHPUnit_Framework_TestListener { public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { // Only run specific test suites if ($suite->getName() == 'MyTestSuite') { $suite->addTestSuite('MyTestCase3'); } } } class MyTestCase3 extends PHPUnit_Framework_TestCase { public function testSomethingNew() { $this->assertNotEmpty('hello'); } } // Register the listener with PHPUnit PHPUnit_Framework_TestListener_DefaultTestListener::add(new MyTestListener()); // Run all tests PHPUnit_TextUI_TestRunner::run();In this example, we create a custom test listener (MyTestListener) that will automatically add a new test case (MyTestCase3) to the test suite if the suite is named "MyTestSuite". We register the listener with PHPUnit using the add method of the PHPUnit_Framework_TestListener_DefaultTestListener class. Finally, we run all tests using the PHPUnit_TextUI_TestRunner. Package library: PHPUnit
public addTestSuite ( mixed $testClass ) | ||
$testClass | mixed |