kitman's avatar

How to revert data for this unit test

hi,

my fd told me that for every single test we only revert the data that it created for that test, so then we looked at the laravel doc and the only method we can use is "use RefreshDatabase;". but this will clear all the data in every table, I explain why laravel have to do it that way, but he still thinks it is strange, so is there a way we can revert the data that we created for this test, and if not why?

0 likes
1 reply
Nash's avatar
Nash
Best Answer
Level 20

AFAIK, it is common practice to have a separate database for testing that is reset before each test. This could be an in-memory or sqlite database.

Why would you need to leave data in your db? Are you not setting up the data as required for the test? Surely you are not performing unit tests on your production database (potentially dangerous, also the tests could be affected by existing data since they are not performed in a "neutral" environment)? Side note: some would argue that it's not a unit test but an integration test (or some other type of test) if you are using the db.

1 like

Please or to participate in this conversation.