November 2016
Intermediate to advanced
944 pages
21h 1m
English
If we wanted to test the search request handled by the SearchController class, we would certainly want to mock SearchService.
There are two ways of doing this: with a mock or with a stub.
First, we can create a mock object with Mockito:
package masterSpringMvc.search; import masterSpringMvc.MasterSpringMvcApplication; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; ...
Read now
Unlock full access