I am getting following error

PHPUnit\Framework\Exception: PHP Fatal error: Uncaught Error: Class 'Route' not found in /var/www/html/checkout/routes/api.php:24

I have tried answer from Error: Class 'Route' not found in routes.php when testing standalone Laravel package using Orchestra Testbench. It is not working and giving same error.

Below is my XML code:

<filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
            <directory suffix=".php">./routes</directory>
            <exclude>
                <directory >./routes</directory>
                 <file>./routes/api.php</file>
                 <file>./routes/web.php</file>
            </exclude>
        </whitelist>
    </filter>```
3

There are 3 best solutions below

0
On

Partialy fixed by removing from test case

/**
  * @runInSeparateProcess
 */ 

added stderr="true" like bellow

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         stderr="true">
2
On

My guess it becomes of aliases. To fix this try to import use Illuminate\Support\Facades\Route; class in the file where you are defining routes

0
On

Here is my PHPUnit File

 <filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">./app</directory>
        <exclude>
            <directory suffix=".php">/app/Http/Middleware</directory>
            <file>./app/Http/Middleware/RedirectIfAuthenticated.php</file>
        </exclude>
        <exclude>
            <directory suffix=".php">/app/Exceptions</directory>
            <file>./app/Exceptions/Handler.php</file>
        </exclude>
        <exclude>
            <directory suffix=".php">/app/Helpers</directory>
            <file>./app/Helpers/Helpers.php</file>
        </exclude>
        <exclude>
            <directory suffix=".php">/app/Providers</directory>
            <file>./app/Providers/BroadcastServiceProvider.php</file>
            <file>./app/Providers/HttpsProtocolProvider.php</file>
        </exclude>
    </whitelist>
</filter>