Aperiplus Test Runner

A command line script to run SimpleTest test cases (an http UI may be added later).

One of the aims is to avoid having to define lots of test groups using SimpleTest TestSuite::addFile(). That's extra work when you're creating new classes and it's easy to forget to add something. Instead, a single file per project (FrontController) will run all tests either individually or in groups. I've assumed that the organisation of files in the filesystem is all the taxonomy you need to create separately-runnable groups — see below.

Creating a Runner File

Although the runner script can run tests anywhere in the filesystem, different projects will almost certainly have different configuration needs and possibly clashing settings. Hence you'll need a unique runner file per project, each loading the relevant config stuff.

Runner scripts are pretty simple:

<?php    
    
require_once('aperiplus/lib/simpletest/runner.php');

# configure any settings you might need for the code base
# constants, registry values, etc
# ...

exit(call_user_func_array(
    array(new Test, 'getStatus'),
    array()));

A real life example as used by aperiplus can be viewed here. Some values (from a separate config file) are loaded into a registry — but first the script checks to see if a user forgot to define the config file.

In Use

For the rest of this page, I'll assume the new runner file has been saved as "test.php".

First, cd into the dir with your test.php script:

$ cd /your/path/to/the-app

help:

$ php test.php -h

Run all tests in a file or all in a dir (recursive):

$ php test.php foo/file.php
$ php test.php foo/

Note that the script only looks for test cases in files with a ".php" extension. Others will be ignored.

Run single test cases:

$ php test.php foo/file.php MyTestCase 

...or just a single test method:

$ php test.php foo/file.php MyTestCase::testFoo

Although the script should run normal SimpleTest test cases (??), your test case classes must inherit from AperiTestCase (rather than UnitTestCase) in order to use the single-method-only option.

Options:

Examples:

$ php test.php -t foo/
$ php test.php -p foo/file.php

Test Groups

To create test groups, just organise test case classes in files and/or dirs; the runner script simply collects all test cases in/under the given path.

There is no way to define groups other than this and it's unlikely I'd want to add anything more complicated. Strictly speaking, there is only one group that really matters: the full test suite. The more often this is run the better. Although it can be useful to run smaller groups, or even single test methods, this has to be balanced against the unseen effects the new code might have on the application as a whole. It's possible that you could have introduced a problem which doesn't show up in a limited test run.

For this reason, I don't think there's a need for any particularly sophisticated grouping mechanism; the filesystem will do. You've probably already defined all the groups you need simply by the way you've organised test cases into files and dirs. If not, you may not like this script.

Aperiplus Test Suite

If you want to run the Aperiplus test suite, the runner file can be found at: aperiplus/test.php. To run all tests:

$ cd /your/path/to/aperiplus
$ php test.php lib/

 

SourceForge.net Logo