Testing GET API interactions with Oracle
We have some GET APIs written in Python which fetches some data from Oracle i.e. there are some SQLs written in Python APIs through which it fetches the data from Oracle. This is not consumed by an external system but the response of this API is passed to the UI which displays the data.
I need to write some end to end test cases for this API which would check whether the data it fetches from the Oracle is correct or not. This would mean I would need to actually check the SQLs that are written in the API. I have figured out 2 ways to do this :
- To mock the data in database, save the expected data and compare it against the API response.
- To write SQLs and fetch the data from that SQLs and compare it against API response.
I personally prefer the 2nd way, but this would mean parallel development. How do you do it in your organization ?
Marcee last edited by
What you actually have to do is prepare your test data. Depending on the project, access rights and so on, you got a couple of options:
- Keep some test data in the database, have a script to recreate it whenever necessary,
- Recreate all test data via some script before all tests are run, cleanup afterwards,
- Have a pre and post condition in each test, which will create the data before execution and cleanup afterwards.
I usually write tests that create and cleanup after them, I would suggest you do the same. So instead of validating SQL query vs API, what you should do is:
- Create test data in precondition via SQL,
- Have your test consume the test data,
- Clean up after the test, remove the test data.