title: PHPUnit Laravel InvalidArgumentException: Unable to locate factory with name [default] [App\User]
body: <p>I have a setup function in a test which does the following</p>
  
  <pre><code>function setUp()
  {
      $this-&gt;user = factory(User::class)-&gt;create();
  }
  </code></pre>
  
  <p>ofcourse I used "use App\User;" at the very top.</p>
  
  <p>This is my model factory</p>
  
  <pre><code>/** @var \Illuminate\Database\Eloquent\Factory $factory */
  $factory-&gt;define(App\User::class, function (Faker\Generator $faker) {
      static $password;
  
      return [
          'name' =&gt; $faker-&gt;name,
          'email' =&gt; $faker-&gt;unique()-&gt;safeEmail,
          'password' =&gt; $password ?: $password = bcrypt('secret'),
          'remember_token' =&gt; str_random(10),
      ];
  });
  </code></pre>
  
  <p>When runnning phpunit i get the error</p>
  
  <pre><code>InvalidArgumentException: Unable to locate factory with name [default] [App\User].
  </code></pre>
  
  <p>HOWEVER: If I go to php artisan tinker an run </p>
  
  <pre><code>factory(User::class)-&gt;create();
  </code></pre>
  
  <p>it works ... I tried App\User::class and other stuff and even putting it inside the test directly instead of the setUp method. The weird part is that another factory within the same file is working.</p>