24
votes

I'm having some problems with phpunit. When I execute a test, phpunit give me these warnings:

1) Warning No tests found in class "Illuminate\Foundation\Testing\TestCase".

2) Warning No tests found in class "TestCase".

But I'd like to ignore these files, so that phpunit won't try to run tests from them.

How to do that?

5

5 Answers

48
votes

Hopefully by now you found the answer but if you haven't this might help:

Hmm - make sure that the filenames and class names all match up. For example, no FooTest class with a filename of BarTest.php.

Also, are you positive that you have a *Test.php file within the app/tests directory?

[...]

That was it, i.e. one of my tests had a typo in the filename-vs-classname. Odd that typo kicks a warning in the TestCase classes and instead of flagging the class that actually caused it.

From: https://laracasts.com/forum/?p=83-warnings-for-testcase-illuminate-foundation-testing-testcase/0

Basically, make sure your file names and class names match up. I was banging my head on this one too.

44
votes

An additional solution could be to make the TestCase class abstract. By doing so, PHPUnit will not try to find any tests in it.

abstract class TestCase {

4
votes

For me, the problem was that the class name did not match the file name, so a class defined as

class ExampleTest {

was not named ExampleTest.php.

If there are certain test files you would want to ignore, then go into the phpunit.xml file and inside

<testsuite name="Application Test Suite">
    <directory></directory>
</testsuite>

replace the directory tags with tags and specify the specific test file you want to use.

0
votes

For me, I had a convention mistake. The solution was changing the class name, and file, from TestFoo to FooTest.

0
votes

I was also facing the same problem. I've checked that my file name and class name were the same as AuthTest.php and AuthTest respectively.

But still I was getting the same warning maybe because I've renamed the ExampleTest.php to AuthTest.php.

Anyways I've deleted the previous file and used the php artisan make:test AuthTest and it worked.