#Pest test randomly failing

13 messages · Page 1 of 1 (latest)

placid quiver
#

I'm putting together a Filament admin panel and I've build out a good number of tests using Pest. When I run these sometimes a random one will fail. However if I run it again they'll all pass. Is this a common thing with testing or are my factories a bit clunky somehow. Testing is new to me so I may be missing something. I refresh my DB for each test.

deep badge
#

You probably have some randomness in your seeders or something like that and it rises some cases in which your tests are failing

#

make sure to either write proper handling for those cases or update your seeders if it's not a desired thing. Probably also make sure you're not calling any 3rd party services or something

pure lantern
#

Find the flaky test and run it multiple times. If you're unlucky, the flakiness depends on other tests as well, probably by using a shared resource like cache, or perhaps for time-based reasons.

#

If you're asserting timestamps, make sure you freeze the time.

deep badge
#

ah cache is a good point too aPES_Think

#

now it got me worried for my tests thinkies

pure lantern
#

You probably have cache_driver=array for tests, meaning no cache between tests

placid quiver
#

Ok thanks for the comments. phpunit has cach_driver=array as the setup should I change this? I'll go and run the flaky test, just gotta dive into the pest docs to see what command to use. 🙂

pure lantern
#

Cache driver is good, and of course don't mess with any settings before you see what the exact test failure is. Feel free to post the test-failure here.

placid quiver
#

Ok so this is what I get randomly does not contain "wire:key="fIu0wxAw9ksjQr3NLKPj.table.records.06258d0a-dfcc-4a87-bf29-27ff9fe353b6"".

#

My factory is this: 'full_name' => fake()->company(),