Summer Sale! All accounts are 50% off this week.

Rretzko's avatar
Level 15

Test\TestCase not found

Hi - I'm trying to write a basic test in Laravel, but am getting the error: Uncaught Error: Class "Tests\TestCase" not found in C:\xampp\htdocs\tdrwip\tests\Feature\Libraries\LibraryIndexTest.php:9. Here's the code:

<?php

namespace Tests\Feature\Libraries;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class LibraryIndexTest extends TestCase
{
    /**
     * A basic feature test example.
     *
     * @return void
     */
    public function test_example()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

Using phpstorm, when I right-click the TestCase -> GoTo -> Super Method, nothing happens. My tests directory is: /tests

  • Feature
  • Unit
  • CreatesApplication.php
  • TestCase.php

My composer.json includes: "autoload-dev": { "psr-4": { "Tests\": "tests/" } I'm on Laravel 8.83.6. Has anyone else run into this and found a cause/fix? Thanks! },

0 likes
5 replies
Sinnbeck's avatar

Maybe there is a problem with the Tests\TestCase file. Open it and check it for errors

Rretzko's avatar
Level 15

Thanks for the reply @sinnbeck . The Tests\TestCase looks fine and no errors reported; it's a simple gateway file:

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}
Sinnbeck's avatar

@Rretzko Strange. I tried copying that content into my own testcase file in a project and it works fine in phpstorm. Maybe try invalidating indexes, or composer dump-autoload

1 like
Rretzko's avatar
Rretzko
OP
Best Answer
Level 15

Thanks again @sinnbeck. That didn't fix the problem, so I created a new environment, re-installed the application, and it is working as expected now. It doesn't help me understand the problem or find a real solution, but the train is back on the tracks again1

Sinnbeck's avatar

@Rretzko ah ok good. If you still have the repo you can put it on github if you want to have a look

Please or to participate in this conversation.