title: In Laravel, how can I clear my database after my test class is done running?
body: <p>I have a really large database that I want to introduce testing into and I have been experimenting on ways to approach it.</p>
  <p>If I were to run the full migrate:fresh it would take about a minute to create the entire schema. To seed this database it would likely take &gt;5 minutes. My thought was to preload a DB schema into a test database ahead of time, before the tests even start running. Then I was thinking I would seed portions of data as I need it.</p>
  <p>This project has multiple domains and it is a DDD design. I'm currently thinking that each domain will have at least one testcase that extends laravels BaseTestcase.</p>
  <p>The problem I'm having is that I am not able to clear the data from the database. Here's an example of what a testcase might look like for one of my domains:</p>
  <pre class="lang-php prettyprint-override"><code>    use CreatesApplication;
      use RefreshDatabase;
      use ActingAsUser;
      use HasTestHelpers;
  
      /**
       * Refresh a conventional test database.
       *
       * @return void
       */
      protected function refreshTestDatabase()
      {
          if (! RefreshDatabaseState::$migrated) {
              $this-&gt;artisan('db:seed --class=CourseTestSeeder');
  
              $this-&gt;app[Kernel::class]-&gt;setArtisan(null);
  
              RefreshDatabaseState::$migrated = true;
          }
  
          $this-&gt;beginDatabaseTransaction();
      }
  
      public static function tearDownAfterClass(): void
      {
          CourseTestSeeder::clear();
      }
  </code></pre>
  <p>This particular domains depends on Course data. I put together a CourseTestSeeder that will seed all the data needed for this domain. This part works great. The problem is that when I try to do a tearDownAfterClass I receive the following error:</p>
  <pre><code>Exception in tearDownAfterClass
    Target class [db] does not exist.
  
    at vendor/phpunit/phpunit/phpunit:98
       94▕ unset($options);
       95▕
       96▕ require PHPUNIT_COMPOSER_INSTALL;
       97▕
    ➜  98▕ PHPUnit\TextUI\Command::main();
       99▕
  </code></pre>
  <p>How can I clear the db after my tests run? Is there a better way to do this?</p>
  <p>If this is not a good approach, I also welcome feedback on that.</p>