membersound:
¿Es posible sustituir un heredada @MockBean
con lo real @Bean
?
Tengo una clase abstracta que define muchas configuraciones y una configuración para todas las ITests. Sólo para una sola prueba que quiero hacer uso del grano real, y no se utiliza el burlado. Pero aún así heredar el resto de la configuración.
@Service
public class WrapperService {
@Autowired
private SomeService some;
}
@RunWith(SpringRunner.class)
@SpringBootTest(...)
public abstract class AbstractITest {
//many more complex configurations
@MockBean
private SomeService service;
}
public class WrapperServiceITest extends AbstractITest {
//usage of SomeService should not be mocked
//when calling WrapperService
//using spy did not work, as suggested in the comments
@SpyBean
private SomeService service;;
}
membersound:
Encontrado una forma usando una prueba @Configuration
condicional en una propiedad, y anulando esa propiedad en el impl con @TestPropertySource
:
public abstrac class AbstractITest {
@TestConfiguration //important, do not use @Configuration!
@ConditionalOnProperty(value = "someservice.mock", matchIfMissing = true)
public static class SomeServiceMockConfig {
@MockBean
private SomeService some;
}
}
@TestPropertySource(properties = "someservice.mock=false")
public class WrapperServiceITest extends AbstractITest {
//SomeService will not be mocked
}