Data preparation for integration testing - Is it recommended to use Mocks?


I’m working to initiate an integration testing project and I was trying to think about the best practices for data preparation, is it recommended to use data mocking or is there any better solutions like using the real app data?



@hiba Thats a good topic to discuss.
I had similar challenges in one of my project and I handled it via hybrid model.
For example. first name, last name, email address etc are not validated during other subsystems so I mocked all those parameters whereas Address need to be valid b subsystems as based on the address service provide to end user so mocking address not helped and required actual address which will be downloaded and provided into excel to use end to end integration testing.

You can also do pre-requisite to prepare your data preparation.


@theology Well, thanks for this valuable experience. My problem with mocks for integration testing is related to the fact that I want to test the actual integration if it’s working well. Hence, it would be an opportunity for having wrong assumptions if I mocked the database in case I want to test the integration between API and the Database


Hi Hiba

From my experience, the ideal approach is to use both at different points in the development lifecycle.

Initially while the application or service is being developed, or changed and within your dev environments, you may prefer to use mocks or stubs to behave like to real service. This will ensure that development isn’t blocked in case that the real API is down or has some restrictions in terms of usage. It will also help in testing error scenarios where you have more control over the responses of the service.

When you deploy to higher environments at this point you would be better off using the real service(s) to perform integrations tests to give you the confidence that your application is behaving correctly when integrated.

Ideally you could have a suite of integration tests that can run against either the mock or real services and both are run as the application is deployed through your environments.



thanks for sharing this, I agree about both points and I’m thinking now about the best approach about data preparation once we move to a higher environment.

1 Like