Skip to content

Factories don't work in _unit_tests #30879

@EmmaPurple

Description

@EmmaPurple
  • Laravel Version: 6.8.0
  • PHP Version: 7.3.9
  • PHPUnit Version: 8.5.0
  • Database Driver & Version: MariaDb 10.4.6

Description:

Using factories in Unit-tests don't work in a new laravel project. Perhaps it is intended, but then it should be in the documentation. And I believe I have used factories in Unittests before...

Steps To Reproduce:

  1. Create a new laravel project
  2. Change the 'tests > Unit > ExampleTest > testExample' to
    public function testBasicTest()
    {
        factory('App\User')->make();
        $this->assertTrue(true);
    }
  1. Run the Test

Now the tests throws an error, saying:
InvalidArgumentException: Unable to locate factory with name [default] [App\User].

As expected it does not make a difference if using the User::class Property as param

Using the same code in featuretests works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions