Seems the problem is that the status is a random number between 1 and 3. My guess is that your post route does not set the same number. So 1 in 3 chance for it to pass. Show the method please
Jul 29, 2022
9
Level 2
Failed asserting that a row in the table [employees] matches the attributes
Hello Everyone,
I am following Build A Laravel App With TDD series from laracasts . Though it's a old series . I am getting an error while testing. Sometimes I get an error on a test and sometimes test passes. I am unable to fix the error.
When I get an error it says
Failed asserting that a row in the table [employees] matches the attributes
This is my code for test
class EmployeeTest extends TestCase
{
use withFaker, RefreshDatabase;
public function test_create_employee()
{
$this->withoutExceptionHandling();
$attributes = [
'name' => $this->faker->name,
'office_id' => $this->faker->numerify('3###'),
'designation' => $this->faker->jobTitle(),
'email' => $this->faker->unique()->safeEmail(),
'mobile' => $this->faker->numerify('017########'),
'status' => $this->faker->numberBetween(1, 3),
];
$this->post('employee', $attributes);
$this->assertDatabaseHas('employees', $attributes);
}
}
This is the error
If i run the test several time the test pass too.
Please or to participate in this conversation.