I have some confusion about API automation testing in Cypress. If we use a real database to handle the DELETE request without mocking data, How to test with the same data set to run the tests again or how it works in ci/cd?
I tried to mock data and test but it does not seem to be the best way to test some complex queries. Could any one give me any solution on this?
If you desire to run E2E tests, to be as consistent as possible, you need to always have the same initialization of the data.
To get always the same data, you have multiple options. I will only present 3 possible solutions:
You can create the item to delete with the automatic test.
Example: For the deletion of an item in a to-do list, you could easily create the item to delete right before.
You can run requests to your backend that will create the initial state of your test before each state.
Example: For the deletion of a to-do board full of lists, it would be easier to push programmatically the initial state of the board through a request to the backend.
You can use a snapshot of your E2E database and every time, you need to reload this database (I don't recommend this solution except if the others aren't possible)
Of course, there is many other possiblities