Phpunit tests gives warning no tests found in class
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Title: Understanding and Resolving PHPUnit Tests Giving "No Tests Found" Warning
Body:
When working on Laravel projects or developing tests for your application, you may come across issues where your PHPUnit test command produces a warning indicating "No tests found in class." This issue is usually due to multiple reasons. In this comprehensive blog post, we will discuss the possible causes and solutions for this problem.
1. Missing Test Case Methods: Ensure your test class contains at least one test method. For example, in our case, the PostsTest class doesn't have any actual tests, only setup functions. Make sure to define a test method that will be executed as part of the PHPUnit test run.
2. Incorrect Classname and Filename: Ensure your test class name matches the filename where the class is defined. For instance, if your test class named PostsTest resides in PostsTest.php file, everything should work properly. However, if the filename is incorrect or different from the class name, PHPUnit won't be able to recognize and execute your tests.
3. Test Case Extension: Verify that you are extending the correct base class for Laravel testing. In our example, ApiTester seems appropriate for API testing; however, if it's not related to the application code being tested or is incorrect, this could lead to issues during PHPUnit execution. Ensure to extend a suitable test case class such as TestCase or FeatureTestCase based on your requirements.
4. Laravel or PHPUnit Configuration Issues: Incorrect configuration of Laravel or PHPUnit can potentially cause these issues. Firstly, update the PHP version and ensure it's compatible with Laravel and PHPUnit. Secondly, confirm that you have set up the necessary dependencies for both Laravel and PHPUnit in your project. Double-check your project’s composer.json file contains the required packages and their correct versions.
5. Incorrect Test Execution Command: The given command
phpunit should be used to execute all tests within the project. If you are only trying to run a specific class or test method, use the phpunit path/to/file.php --filter=PostsTest::it_fetches_posts command.
6. PHPUnit Version Mismatch: Ensure that the PHPUnit version installed on your system matches the requirements of Laravel and any other dependencies you're using in your project. Discrepancies can cause unexpected errors like this one.
To summarize, to resolve issues where your PHPUnit tests give a warning "No tests found in class," first check if the test case class name and filename match, if the test class extends an appropriate Laravel testing class, and whether you've followed the correct configuration steps for Laravel and PHPUnit. Finally, make sure to use the correct command to execute your tests. If all of these are aligned, then the issue might be with your project or application code, which could require further investigation and debugging.