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 calledMyTestSuite
which extends thePHPUnit_Framework_TestSuite
class.public static function suite()
- This line creates a public static function calledsuite
which will be used to create the testsuite.$suite = new PHPUnit_Framework_TestSuite('MyTestSuite');
- This line creates a new instance of thePHPUnit_Framework_TestSuite
class and assigns it to the$suite
variable.$suite->addTestSuite('MyTestCase1');
- This line adds theMyTestCase1
test case to the$suite
testsuite.$suite->addTestSuite('MyTestCase2');
- This line adds theMyTestCase2
test case to the$suite
testsuite.return $suite;
- This line returns the$suite
testsuite.
Helpful links
More of Phpunit
- How to show warnings in PHPUnit?
- How to stop PHPUnit on failure?
- How to skip a PHPUnit test?
- How to install PHPUnit with a PHAR file?
- What are PHPUnit required extensions
- How to use named arguments in PHPUnit?
- How to mock a method with different arguments in PHPUnit?
- How to run tests in parallel with PHPUnit?
- How to ignore a test in PHPUnit?
- How to test private methods in PHPUnit?
See more codes...