Support the ongoing development of Laravel.io →
Testing Laravel API
Last updated 1 week ago.
0

RefreshDatabase runs tests inside a transaction or re-migrates the database, which can leave extra records (seeded data, globally scoped models, or observer-created users) visible during the request.

Because of that, your search endpoint returns more than one user, causing assertJsonCount(1, 'data') to fail.

DatabaseTruncation fully wipes the tables between tests, so only the factory-created user exists and the assertion passes.

0
Solution selected by @mina20088

@miladghorbani1999 the problem that it slows the testing , on the other hand when I used DatabaseRefresh trait with SQLite it works without any problem

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2026 Laravel.io - All rights reserved.