简体   繁体   中英

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!

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

It is trying to find the file suites/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.

Maybe in the InstallDbTest.php file you are missing:

<?php
...

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 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM