lundi 24 août 2020

Should I mock the repository during integration test of controller?

I've got a microservice project where we use integration tests that do not mock repositories. So we have a test class for each controller and each test class creates a new application context because we don't remove the data written by previous tests. Moreover, the tests are based on ordering(we need to create entities in DB first and then test it).

The question is: Wouldn't it be better to mock the repository for each controller test class and create separate integration tests for persistence(e.g. by using TestEntityManager)? This approach will get rid of test ordering and make it possible to share the application context between controller test classes.

Aucun commentaire:

Enregistrer un commentaire