Phpunit: No tests found in TestBase class when ChildTest is not spelled correclty

Created on 25 Aug 2017  ·  4Comments  ·  Source: sebastianbergmann/phpunit

| Q | A
| --------------------| ---------------
| PHPUnit version | 5.7.21
| PHP version | 5.6.30
| Installation Method | Composer

Hi,

I have found a strange behavior in PHPUnit when I don't write my class name correctly. I think it's related to #731

Situation:

  • I have 2 classes.

    • A TestBase.php file that contains a TestBase class that does not end with _Test_ so that shouldn't be called

    • A ChildTest.php file that contains a MyTest class (wrong name then). When I do phpunit tests/ I get : No tests found in class "Edyan\MyPackage\Tests\TestBase" and my tests contained in the class are well executed.

  • If I set TestBase as abstract : no problem

  • If I rename MyTest to ChildTest : no problem

Any idea ?
Thanks

Most helpful comment

Base classes such as your TestBase class that do not contain any tests of their own should be declared abstract. Then PHPUnit does not try to run their non-existant tests.

All 4 comments

Since you're using composer, it uses a PSR-0/4 autoloader. According to PSR standard, a mismatching between class and file name is an error.

Thanks for your answer,

Does that mean that PHPUnit shouldn't load a class that has a different name than the file ? With composer if you try to load the class ABC located into CDE.php you'll get an error.

Thanks

Base classes such as your TestBase class that do not contain any tests of their own should be declared abstract. Then PHPUnit does not try to run their non-existant tests.

That's clear, thanks for the best practice

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastianbergmann picture sebastianbergmann  ·  4Comments

kunjalpopat picture kunjalpopat  ·  4Comments

keradus picture keradus  ·  4Comments

stemis picture stemis  ·  3Comments

ezzatron picture ezzatron  ·  3Comments