We a have test repo outside of the app repo and we can generate data by either having direct SQL queries or through API calls (http requests).

We've been entertaining the idea of switching over to using external APIs (http requests).

Is there a clear preference as to which approach is better?

2 Answers 2


Using HTTP requests to populate data in your repo adds another potential layer for failure, as well as a bit of extra latency. If the API changes, then you will be required to change your test setups as well, for instance.

By the same token; if your API dictates how things are stored in the SQL repo, then if the SQL schema changes, you will need to modify the queries directly for the test setups, while if you used the API, you would not.

To me those are the main pros/cons you need to weigh, I would choose whichever is less likely to change, the SQL schema, or the API.


As @JSarwer points above, you need to find out what's the most stable layer in your organization, and whether performance is a concern or not.

In general terms, however, API means Application Programming Interface, which means that's the layer you should use to develop applications. Integration tests are no different. Your database schema and SQL queries could be just an implementation detail. And you should never code against implementations, but against interfaces.

But maybe your organization has a promise to use the database layer as the programming interface, and the schema is guaranteed to be very stable. In that case, using the database directly could work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.