【发布时间】:2019-04-19 17:40:02
【问题描述】:
我有 spring-boot 和 REST API 项目。我正在尝试测试 findAll @GET 操作。以下是显示所有记录方法的测试用例。
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.standaloneSetup(batchJobConfigController).build();
}
@Test
public void testBatchJobConfigs() throws Exception {
BatchJobConfigDTO mockBatchJobConfigDTO = new BatchJobConfigDTO("Doctor", "ER Doctor", "Started", "Full Time");
batchJobConfigDTOs.add(mockBatchJobConfigDTO);
when(mockBatchJobConfigService.findAllBatchJobConfigs()).thenReturn(batchJobConfigDTOs);
mockMvc.perform(get("/configs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.jobNm", Matchers.is("Enginerring")))
.andExpect(MockMvcResultMatchers.jsonPath("$.jobDesc", Matchers.is("Coding, Testing and stuff")))
.andExpect(MockMvcResultMatchers.jsonPath("$.status", Matchers.is("Progress")))
.andExpect(MockMvcResultMatchers.jsonPath("$.jobType", Matchers.is("INFA")));
verify(mockBatchJobConfigService, times(1)).findAllBatchJobConfigs();
verifyNoMoreInteractions(mockBatchJobConfigService);
}
我正在 JUnit4 中运行以下内容。可能是什么原因?
java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.controller.BatchJobConfigControllerTest]:
【问题讨论】:
-
@RunWith(SpringRunner.class) @SpringBootTest @WebMvcTest(value = BatchJobConfigController.class, secure = false) public class BatchJobConfigControllerTest {//上面的方法在这里............ .......}
标签: java rest spring-boot junit4