'Run unit test and Integration test in same application Spring Boot
I have spring boot application with REST APIs. There are three layers as @Controller, @Service and @Repositiry. I need to write unit test cases to each layer and integration test with all layers including databases.
Unit test cases write using @MockBean s. They should run with mock objects. Integration test cases should run with actual objects.
But both cases use mock object. So integration test failed.
How I use mock object to unit test and actual object to integration test.
Solution 1:[1]
You need to separate 2 test, those 2 tests type weren't go along with each other.
Unit test mock object -> testClass -> assert
So you just thinking of what do the method do and Mock all around other methods that depend with the method you tested.
Integration test Real object -> whole process -> real result This is like full loop on single workflow of your service. No need to check any value along the way just focus only response of even data that saved into database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | paranaaan |
