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 :

    1. To mock the data in database, save the expected data and compare it against the API response.
    2. 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 ?



  • 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:

    1. Keep some test data in the database, have a script to recreate it whenever necessary,
    2. Recreate all test data via some script before all tests are run, cleanup afterwards,
    3. 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:

    1. Create test data in precondition via SQL,
    2. Have your test consume the test data,
    3. Clean up after the test, remove the test data.


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2