Intermittent failures when testing activity logs #1155
-
Hi guys, I am writing a feature test to test if activity logging works correctly. Unfortunately, the test fails intermittently approx. every fifth time. I am pretty sure this is because the event firing takes some time and the My test: test('log entry is created if a gig is created', function () {
$gig = Gig::factory()->create();
$activity = Activity::all()->last();
expect($activity->subject_id)->toBe($gig->id);
expect($activity->description)->toBe('gig_created');
expect(DB::table('activity_log')->where('description', 'gig_created')->count())
->toBe(1);
}); As said, the test is successful approx. 4 out of 5 times. But sometimes it fails with the following error as the Tests\Feature\ActivityLogTest > log entry is created if the gig response status is set initially Attempt to read property "subject_id" on null What's the best practice to test something like this and prevent this error from happening? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Nevermind, I figured it out myself. There was a random parameter in my Factory that sometimes prevented the log entry from being created. Thanks for the great package! |
Beta Was this translation helpful? Give feedback.
Nevermind, I figured it out myself. There was a random parameter in my Factory that sometimes prevented the log entry from being created.
Thanks for the great package!