Проблема с WebMvcTest в сочетании с @SpringBootTest - PullRequest
0 голосов
/ 01 мая 2020

Я использую весеннюю загрузку 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)]

1 Ответ

0 голосов
/ 01 мая 2020

У меня есть причина проблемы. Это происходит потому, что «WebMvcTest» использует «@BootstrapWith (WebMvcTestContextBootstrapper.class)» и SpringBootTest, ссылаясь на «@BootstrapWith (SpringBootTestContextBootstrapper.class)» и, следовательно, ошибку.

...