我有一些测试失败了,Error creating bean with name 'entityManagerFactory'这个答案为我解决了https://stackoverflow.com/a/47504698/6945345但破坏了我的控制器测试Could not instantiate JAXBContext for class [class org.springframework.hateoas.PagedResources]: Implementation of JAXB-API has not been found on module path or classpath.这是因为我认为@WebMvcTest没有选择 JAXB-API。我该怎么做才能以最佳方式解决此问题?给出异常的控制器测试类:@RunWith(SpringRunner.class)@WebMvcTest(BiodiversityController.class)@Import(SpecieResourceAssembler.class)public class BiodiversityControllerTest { @MockBean private SpecieService specieService; @Autowired private MockMvc mockMvc; @Autowired private SpecieResourceAssembler specieResourceAssembler; @Before public void setup() { mockMvc = MockMvcBuilders.standaloneSetup(new BiodiversityController(specieService, specieResourceAssembler)) .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) .build(); } @Test public void getAllSpecies_ShouldReturnSpecies() throws Exception { PageRequest pageRequest = PageRequest.of(0, 20); given(specieService.getAllSpecies(pageRequest)).willReturn(new PageImpl<>( Collections.singletonList(createAnimaliaOrestias()), pageRequest, 1)); mockMvc.perform(MockMvcRequestBuilders.get("/species?page=0&size=20")) .andExpect(status().isOk()) .andExpect(jsonPath("$.content", hasSize(1))) .andExpect(jsonPath("$.content.[0].name").value(NAME_ORESTIAS)); verify(specieService).getAllSpecies(pageRequest); }}
添加回答
举报
0/150
提交
取消