testing multiple folders

FMaz008 picture FMaz008 · Mar 31, 2011 · Viewed 9.7k times · Source

I use PHPUnit 3.5.12, netbean 6.9, and git submodules in my project.

So my folder architecture looks like that:

lib/
lib/submodule1
lib/submodule1/src
lib/submodule1/tests
lib/submodule2
lib/submodule2/src
lib/submodule2/tests
src/
tests/

Considering that my main test folder (with phpunit_netbean.xml and bootstrap.php) is in the /tests/ folder; How can I be able to run the tests in /lib/*/tests/ too ?

I've look at testsuite, but I'm unable to get it working. So far I've tried the following configuration in my tests/phpunit_netbean.xml file:

<?xml version="1.0"?>
<phpunit
    bootstrap="./bootstrap.php"
    strict="true"
    stopOnError="false"
    stopOnFailure="false"
    stopOnIncomplete="false"
    stopOnSkipped="false"
    colors="false"
    verbose="true"
    >

    <testsuites>
        <testsuite name="modules">
            <directory>../lib/*</directory>
        </testsuite>
    </testsuites>

</phpunit>

And when I hit ALT+F6 in Netbean, I only have the tests from /tests that are run. Same thing with:

/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here

Also, I've tried this:

/tests$ phpunit -c phpunit_netbean.xml --testdox --loader modules ./
PHPUnit 3.5.12 by Sebastian Bergmann.

Could not use "modules" as loader.

Answer

Gordon picture Gordon · Mar 31, 2011

Have a look at the Appendix for your PHPUnit config file. You can tell PHPUnit which folders to include:

<testsuites>
    <testsuite name="Submodules">
        <directory suffix="Test.php">../lib/*</directory>
    </testsuite>
</testsuites>

When you run this, PHPUnit should recursively iterate over all folders in lib and consider all files ending in Test.php as UnitTests. The name of the testsuite is irrelevant. To ease authoring of the XML file, consider using my phpunit-schema file.

There is some additional information to this in the PHPUnit Manual Chapter: Composing a Test Suite Using the Filesystem . Netbeans has an input dialog in which you can specify the path to the phpUnit.xml and any custom TestSuite Class.

Here is an example project: https://github.com/gooh/sample

C:\Users\Gordon\Desktop\demo\tests>phpunit --testdox
PHPUnit 3.5.13 by Sebastian Bergmann.

A
 [x] One

B
 [x] One

My
 [x] One