phpunitHow to create a testsuite in PHPUnit?
Creating a testsuite in PHPUnit is a simple process.
<?php
class MyTestSuite extends PHPUnit_Framework_TestSuite
{
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('MyTestSuite');
$suite->addTestSuite('MyTestCase1');
$suite->addTestSuite('MyTestCase2');
return $suite;
}
}
?>
This example code creates a testsuite called MyTestSuite which contains two test cases MyTestCase1 and MyTestCase2.
class MyTestSuite extends PHPUnit_Framework_TestSuite- This line creates a class calledMyTestSuitewhich extends thePHPUnit_Framework_TestSuiteclass.public static function suite()- This line creates a public static function calledsuitewhich will be used to create the testsuite.$suite = new PHPUnit_Framework_TestSuite('MyTestSuite');- This line creates a new instance of thePHPUnit_Framework_TestSuiteclass and assigns it to the$suitevariable.$suite->addTestSuite('MyTestCase1');- This line adds theMyTestCase1test case to the$suitetestsuite.$suite->addTestSuite('MyTestCase2');- This line adds theMyTestCase2test case to the$suitetestsuite.return $suite;- This line returns the$suitetestsuite.
Helpful links
More of Phpunit
- How to generate a JUnit report in PHPUnit?
- How to clear the PHPUnit cache?
- How to show warnings in PHPUnit?
- How to skip a PHPUnit test?
- How to run tests in parallel with PHPUnit?
- How to use hooks in PHPUnit?
- How to stop PHPUnit on failure?
- How to mock with PHPUnit?
- What are PHPUnit required extensions
- How to run all PHPUnit tests?
See more codes...