nsvir
nsvir

Reputation: 8961

phpunit no tests executed

I have a 'No tests executed' with phpunit..

This line works

$ phpunit install/InstallDbTest.php
...
<result expected>
...

$ cat suites/installtests.xml   
<phpunit>
    <testsuites>
        <testsuite name="database">
            <file>install/InstallDbTest.php</file>
        </testsuite>
    </testsuites>
</phpunit>

$ phpunit -c suites/installtests.xml 
PHPUnit 4.7.4 by Sebastian Bergmann and contributors.



Time: 130 ms, Memory: 11.25Mb

No tests executed!

Does anyone can tell me what I am doing wrong ?

Thanks in advance!

Upvotes: 3

Views: 7582

Answers (3)

Pierre Lem&#233;e
Pierre Lem&#233;e

Reputation: 342

For those of you who you use a different bootstrap file than the Composer's autoload file, make sure you don't use one of your test case classes.

Indeed, PHPUnit (version 6.2 in my case) add to the running TestSuite all PHP files for which no class is loaded yet (see how it's done in the code). From the TestSuite::addTestFile($filename) method:

$classes = get_declared_classes();
$filename   = Fileloader::checkAndLoad($filename);
$newClasses = \array_diff(\get_declared_classes(), $classes);

So if your class already belong to the get_declared_classes it will be ignored.

To summarize: don't use your test class before ;)

Upvotes: 0

simhumileco
simhumileco

Reputation: 34545

Maybe in the InstallDbTest.php file you are missing:

<?php
...

Upvotes: 0

Schleis
Schleis

Reputation: 43700

You need to correct the path in your phpunit.xml.

It is trying to find the filesuites/install/InstallDbTest.php. Since the file doesn't exist, no tests are run and you get the message.

Change the configuration to the following:

<phpunit>
    <testsuites>
        <testsuite name="database">
            <file>../install/InstallDbTest.php</file>
        </testsuite>
    </testsuites>
</phpunit>

File paths in phpunit.xml are all relative to the location of the xml file.

Upvotes: 9

Related Questions