November 2018
Intermediate to advanced
388 pages
9h 5m
English
We use MockitoJUnitRunner to run the unit test. We inject the required dependencies, such as the PersonController and PersonServiceImpl instances, by mocking the classes. We mock the ResponseBuilder class. We also use the @InjectMocks annotation to inject the serviceImpl instance into the controller object. This is shown in the following code:
@RunWith(MockitoJUnitRunner::class) class CreatePersonTest { @InjectMocks private lateinit var controller: PersonController @Mock private lateinit var serviceImpl: PersonServiceImpl private var builder = mock(Response.ResponseBuilder::class.java)}
Read now
Unlock full access