我目前玩springockito-annotations
,这需要@RunWith
和@ContextConfiguration
注释才能工作。我想将这些注释放在我的测试的超类上,但似乎无法使其工作。@ContextConfiguration不会继承与Springockito
超类:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath:spring/test-context.xml")
public class MyTestSuperclass {
//...
实施例的TestClass:
public class MyTest extends MyTestSuperclass {
@Inject
@ReplaceWithMock
private MyService myService;
//...
有了这个代码,myService
不与一个模拟代替。
但是,如果我将其更改为...
@ContextConfiguration
public class MyTest extends MyTestSuperclass {
//...
...它的工作原理。
有没有办法避免必须将@ContextConfiguration
添加到我的所有测试类?这可能已在更新版本的Spring
/Spring-tests
中修复?从我可以告诉它能够继承超类中的locations
部分而不注释子类,但loader
部分在子类中没有注解的情况下不起作用。我正在使用版本3.2.1.RELEASE的Spring-test
。
下面是一个示例工程中的,显示错误:
http://www.filedropper.com/springockitobug
'弹簧test'因为Spring框架3.0已经支持装载机的继承。所以你绝对不需要重新声明一个空的'@ ContextConfiguration'。 Springockito实现可能存在问题。您是否愿意发布一个最小示例项目来演示此行为(例如,在GitHub上)? –
我认为罪魁祸首是'springockito-annotations',当注释类有一个未注释的超类时,我也遇到了问题,在这些情况下,@ @ ReplaceWithMock没有工作。 – Tobb
增加了一个最小化的项目。在最小的项目中无法重现上述评论中的错误,所以一定是由于其他原因。 – Tobb