【发布时间】:2020-08-16 01:16:53
【问题描述】:
我正在使用 spring-boot 2.1.7-RELEASE 并编写一个测试来测试我的休息控制器。
这是我的测试代码
@RunWith(SpringRunner.class)
@WebMvcTest(MyRESTController.class)
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,classes = {TestConfig.class}
)
public class TestMyRESTController {
@Autowired
private MockMvc mvc;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void getAccount()throws Exception {
mockMvc.perform(get("/user/1"))
.andDo(print())
.andExpect(status().isOk());
}
}
我遇到了异常,有人可以帮我理解我在这里缺少什么吗?
java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.philips.sapphire.infrastructure.SapphireGatewayV1.service.SampleTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)]
【问题讨论】: