是否可以@MockBean用真实的代替继承的@Bean?
我有一个抽象类,它为所有 ITest 定义了许多配置和设置。仅在一次测试中,我想使用真正的 bean,而不是使用模拟的 bean。但仍然继承其余的配置。
@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;;
}
蛊毒传说
相关分类