Я обновил Spring Boot 1.5 до Spring Boot 2.1.8.У меня были некоторые тесты, которые работали, но сейчас не удается.Я также использовал плагин maven-surefire в версии 2.9, и он работал, но я также обновил его до 2.22.0, если это имеет значение.
@ExtendWith(SpringExtension.class)
@WebMvcTest(value = ElementController.class, secure = false)
@ContextConfiguration(classes = TestSite1Config.class)
public class ElementControllerSite1IT {
@Autowired
protected MockMvc mvc;
@MockBean
ElementService elementService;
@BeforeEach
public void setup() {
when(elementService.getElementTable( ... )) //skipping args for brevity
.thenReturn(new ElementTable());
}
@Configuration
public static class TestSite1Config {
@Bean
@Autowired
public ElementController elementController(final ElementService elementService) {
return new ElementController(elementService, new ElementControllerProperties(DeploymentLocation.SITE1));
}
@Test
public void failSite1ValidationWithoutId() throws Exception {
ElementParameters params = getParams(false);
mvc.perform(post("/element")
.contentType(JSON)
.andExpect(status().isBadRequest());
}
//more tests, but doesn't matter.
}
Есть другой класс, как выше, но замените Site1 на Site2.
Существует также класс ElementController & Service.
Я получаю это исключение:
Caused by BeanDefinitionOverrideException: Invalid bean definition with name 'elementController' defined in class path resource [ui/v2/web/ElementControllerSite1IT$TestSite1Config.class]: Cannot register bean definition [Root bean: class [null]; ... defined in class path resource [ui/v2/web/ElementControllerSite1ITConfig.class] for bean 'elementController': There is already [Generic bean: class [ui.v2.web.ElementController]; .. defined in file [...ui/v2/web/ElementController.class]] bound.
Я не писал тесты, это код, который я 'Я унаследовал, в кодовой базе, на которую меня просто навалили.