![]() |
![]() |
![]() |
Unit tester | Simple Test PHP Unit Test Framework | Mock objects |
To run test cases as part of a group, the test cases should really be placed in files without the runner code...
If you have extended any test cases, you can include them as well. In PHP 4...
If you are using PHP 5, you do not need this special directive at all. Simply mark any test cases that should not be run as abstract...
We will call this sample file_test.php. Next we create a group test file, called say my_group_test.php. You will think of a better name I am sure.
We will add the test file using a safe method...
The main problem is that for every test case that we add we will have to require_once() the test code file and manually instantiate each and every test case.
We can save a lot of typing with...
No only that, but you can guarantee that the constructor is run just before the first test method and, in PHP 5, the destructor is run just after the last test method.
There are two things that could go wrong and which require care... The file could already have been parsed by PHP, and so no new classes will have been added. You should make sure that the test cases are only included in this file and no others (Note : with the new autorun functionnality, this problem has now been solved). New test case extension classes that get included will be placed in the group test and run also. You will need to add a SimpleTestOptions::ignore() directive for these classes, or make sure that they are included before the TestSuite::addTestFile() line, or make sure that they are abstract classes.
The above method places all of the test cases into one large group. For larger projects though this may not be flexible enough; you may want to group the tests in all sorts of ways.
To get a more flexible group test we can subclass TestSuite and then instantiate it as needed...
If we still wish to run the original group test, and we don't want all of these little runner files, we can put the test runner code around guard bars when we create each group.
If you already have unit tests for your code or are extending external classes that have tests, it is unlikely that all of the test cases are in SimpleTest format. Fortunately it is possible to incorporate test cases from other unit testers directly into SimpleTest group tests.
Say we have the following PhpUnit test case in the file config_test.php...
![]() |
![]() |
![]() |
Unit tester | Simple Test PHP Unit Test Framework | Mock objects |
Documentation generated on Sun, 04 May 2008 09:21:08 -0500 by phpDocumentor 1.3.0