@RunWith(MockitoJUnitRunner.class)
In this declaration you should write unit test . Unit tests carry out one class, making fun of all the dependencies. Typically, in a test case, you introduce abuse of dependencies:
@Mock private YourDependency yourDependencyMock;
@RunWith(SpringJUnit4ClassRunner.class)
Spring runner is for integration test (component test?). In this type of test, you run a whole bunch of classes, in other words, you test one class with real dependencies (testing a controller with real services, DAO, in-memory database, etc.)
You should probably have two categories in your application. Although we recommend having more unit tests and only a few smoke integration tests, I often found myself more confident in writing almost only integration tests.
As for your second question, you should have:
unit tests for each class (controller, services, DAO) separately with a mockery of all other classes
integration tests for all one CRUD operation. For example, creating a user who uses a controller, service, DAO, and database in memory.
Tomasz Nurkiewicz
source share