Distributed Testing with PHPUnit 3.1

One of the new features in the upcoming PHPUnit 3.1 release is the support for distributed testing through the ability to log test result and code coverage data to a database. This way, the same test suite can be run on different platforms with the results being aggregated in the database. For this to work, however, we need a key in the database that identifies test runs from different machines as being related. A Subversion revision number is a perfect candidate for this. Have a look at the shell script below. It accepts three parameters: the local checkout directory of the project's repository, the number of the revision for which to run the tests, and additional information which can be used to describe the environment in which the test suite is run.

#! /bin/sh CHECKOUT="$1" REVISION="$2" INFO="$3" cd "${CHECKOUT}" svn up -r "${REVISION}" cd "${CHECKOUT}/Tests" phpunit --log-pdo-dsn mysql://user:pass@host/database \ --log-pdo-rev "${REVISION}" \ --log-pdo-info "${INFO}" \ AllTests.php
Invoking the shell script above will update the local checkout of the project's repository to the requested revision, run the test suite, and write test result and code coverage data to a database. This logging of test result and code coverage data to a database is not only of interest when you need distributed testing. It is also the foundation of a, yet to be developed, browser-based application that provides more flexible and versatile reports whereas currently only static HTML files are generated. The database schema can be found here. Feedback related to this new feature is, as always, appreciated.