我想拦截JUnit测试方法。我已经有拦截器为测试准备上下文。我不想在我的拦截器中复制代码。
是否可以告诉SpringJUnit4ClassRunner使用测试类的myTest()实例?类似的东西:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MyConfig.class })
public class MyTest {
@Autowired
private MyInterceptor myInterceptor;
@Autowired
private BeanFactory beanFactory;
@Bean
public MyTest myTest() {
final ProxyFactoryBean proxy = new ProxyFactoryBean();
proxy.setBeanFactory(this.beanFactory);
proxy.setTarget(this);
proxy.addAdvice(this.myInterceptor);
return (MyTest) proxy.getObject();
}
}