Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing multiple folders

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.
like image 845
FMaz008 Avatar asked Mar 31 '11 13:03

FMaz008


2 Answers

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
like image 194
Gordon Avatar answered Oct 12 '22 23:10

Gordon


Let's create a testcase:

mkdir project
mkdir project/tests
mkdir project/modules/
mkdir project/modules/a/
mkdir project/modules/a/tests/
mkdir project/modules/b/
mkdir project/modules/b/tests/

echo "<?php class MyTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/tests/MyTest.php
echo "<?php class MyTwoTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/a/tests/MyTwoTest.php
echo "<?php class MyThreeTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/b/tests/MyThreeTest.php


tree
.
`-- project
    |-- modules
    |   |-- a
    |   |   `-- tests
    |   |       `-- MyTwoTest.php
    |   `-- b
    |       `-- tests
    |           `-- MyThreeTest.php
    `-- tests
        `-- MyTest.php

If you now just run phpunit project it will execute ALL the tests in those folders. So no need for any further configuration.

The only thing that could bite you if you have lasses in your /src/ folders that end in *Test.php, if you don't do that you will not have any issues as far as i can tell.

phpunit project/
PHPUnit 3.5.11 by Sebastian Bergmann.

...

Time: 0 seconds, Memory: 2.75Mb
like image 42
edorian Avatar answered Oct 12 '22 22:10

edorian