Extension:MWUnit/Command-line test runner

From mediawiki.org
Jump to navigation Jump to search

The MWUnit command-line test runner is a maintenance script located in MWUnit/maintenance/runTests.php and can be invoked through the following command:

$ php runTests.php

The following code shows how to run a group of tests with the MWUnit command-line test runner:

extensions:~/MWUnit$ php maintenance/runTests.php --group "foobar"
MWUnit 0.6 by Marijn van Wezel and contributors.


OK (3 tests, 3 assertions)

When invoked, as shown above, MWUnit will run all tests in the group foobar. For each test, the script will print a single character to indicate progress:

Printed when a test succeeds.
Printed when a test has been marked as risky.
Printed when a test has been skipped.
Printed when an assertion failed when running the test.

Command-line options[edit]

We open up the command-line help menu in the following code:

extensions:~/MWUnit$ php maintenance/runTests.php --help

Command-line test runner for MWUnit.

Usage: php runTests.php [--columns|--conf|--dbgroupdefault|--dbpass|--dbuser|--globals|--group|--help|--list-groups|--list-pages|--list-tests|--memory-limit|--mwdebug|--no-progress|--profiler|--quiet|--server|--test|--testdox|--testsuite|--version|--wiki]

Generic maintenance parameters:
    --help (-h): Display this help message
    --quiet (-q): Whether to suppress non-error output
    --conf: Location of LocalSettings.php, if not default
    --wiki: For specifying the wiki ID
    --globals: Output globals at the end of processing for debugging
    --memory-limit: Set a specific memory limit for the script, "max"
        for no limit or "default" to avoid changing it
    --server: The protocol and server name to use in URLs, e.g.
        http://en.wikipedia.org. This is sometimes necessary because server name
        detection may fail in command line scripts.
    --profiler: Profiler output format (usually "text")
    --mwdebug: Enable built-in MediaWiki development settings

Script dependant parameters:
    --dbuser: The DB user to use for this script
    --dbpass: The password to use for this script
    --dbgroupdefault: The default DB group to use.

Script specific parameters:
    --columns: Number of columns to use for progress output
    --covers (-c): Only run tests that cover the specified template
        (without namespace)
    --group (-g): Only run tests from the specified group
    --list-groups: List available test groups
    --list-pages: List available test pages
    --list-tests: List available tests
    --no-progress: Do not display progress
    --test (-t): Only run the specified test
    --testdox (-d): Report test execution progress in TestDox format
    --page (-p): Filter which test page to run
    --version: Prints the version
--columns <n>
Defines the number of columns used for progress output when using the default result printer.
--covers|-c <template>
Only runs the tests that cover the specified template.
--group|-g <group>
Only runs the tests from the specified group.
Lists all available test groups.
Lists all available test pages.
Lists all available tests.
Do not report test progress.
--test|-t <test>
Only runs the specified test.
--page|-p <testsuite>
Only run tests from the specified page (should not include namespace).
Outputs the test progress to the console as agile documentation instead (TestDox format):
extensions:~/MWUnit$ php maintenance/runTests.php --group "foobar" -d
MWUnit 2.0.0 by Marijn van Wezel and contributors.

  ✔ Is Initially Zero
  ✔ Grows Exponentially

OK (2 tests, 34 assertions)

You can read more about the generic maintenance parameters on the corresponding Manual page.