Codex tools: Log in / create account
Contents |
Automated testing is running test cases where manual intervention is not required to run each one. This is usually in the form of writing test suites which have multiple test cases and an xUnit library and command line tool that runs the test suite or suites.
The test suite execution is usually manual, from the developer choosing which suites on the command line to run, but this isn't required. The process could be automated and looked over from time to time to ensure that when the code changed, no problems were introduced.
Everything outside of writing test cases and test suites for the Automattic WordPress Tests repository and running them is outside of the scope of this page. The Automattic WordPress Tests is the formal and authoritative automated testing suite for WordPress. The only way to download is by checking out with Subversion.
The process to add your test suite and test cases to existing suites is to add them to the WordPress Core Trac ticket that has the bug that the test case or suite tests. After you've done this, add "unit-tested" to the keywords of the ticket to inform the lead developers that it has been added.
You must not run the Automattic WordPress Tests on a web site you don't want to be deleted. The Automattic WordPress Tests will remove all WordPress table data before and after it runs the tests, so use a test database for the Automattic WordPress Tests.
The Automattic WordPress Tests environment is WordPress executed as if you were integrating it into another web application. You can't simulate clicks like in a browser, but you can test code as it would be executing in the normal environment.
The current WordPress Tests repository does use Mock Classes, so they are allowed to be used, but not required. At this point the distinction between unit testing and functional testing is pretty blurred, so it is more hybrid testing environment.
You will need to download Subversion before you can continue, if you don't have it already. You should also have an empty MySQL database available. Create a new one if you have to, but you don't want anything in there.
Check out the latest testing suite from http://svn.automattic.com/wordpress-tests/
You might find it easier to just go to that WordPress installation and run the install, so that it creates the wp-config for you. After, you can copy that to the directory below and run the tests. The Automattic WordPress Tests will be looking for wp-config.php in the same directory as wp-test.php. This will also prevent an error in which wp-cron.php will fail, because it can't find wp-config.php in that directory.
The wp-test.php will initiate the automated test suite run. There are some options for which to control what tests are run and other options which trigger how the automated test suite works. Without any arguments, all tests will be run with default options.
The average time for running all of the tests can range between 2 minutes and 7 minutes. This is with the current 399 test cases. When the amount increases, so will the time it will fully take to execute all of the tests.
Note for Windows Users: The wp-test.php makes use of getopt() function, which does not work on Windows before PHP 5.3. You will need to use PHP 5.3.0 or later on Windows or add some hacking to get it to work for you in the previous versions. A Patch is available.
Run the tests by typing: php wp-test.php in the command line.
The first three require a value to be after it, the last two only need to be typed. All arguments are optional.
For example, if you wanted to run the Plugin API Actions test suite, then you would type the following on the command line:
php wp-test.php -t WPTestActions
If you wanted to skip known bugs, you would type the following:
php wp-test.php -s
And if you wanted to force it:
php wp-test.php -s -f
Test cases live in the wp-testcase subdirectory. All files in that directory will be included by default.
Extend the WPTestCase class to ensure your test is run. You can see the code in current tests for examples or read the PHPUnit Pocket Guide.
New test cases should be to the main WordPress trac setting the component to "Unit Tests" these will then get reviewed and added to the subversion repository.