I am currently playing around with springockito-annotations
and this requires @RunWith
and @ContextConfiguration
annotations in order to work. I would like to put these annotations on a superclass of my tests, but can't seem to get it to work.
Superclass:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath:spring/test-context.xml")
public class MyTestSuperclass {
//...
Example testclass:
public class MyTest extends MyTestSuperclass {
@Inject
@ReplaceWithMock
private MyService myService;
//...
With this code, myService
is not replaced with a mock.
But, if I change it to...
@ContextConfiguration
public class MyTest extends MyTestSuperclass {
//...
...it works.
Is there a way to avoid having to add @ContextConfiguration
to all my test classes? Has this perhaps been fixed in a newer version of Spring
/Spring-tests
? From what I can tell it is able to inherit the locations
part from the superclass without annotating the subclass, but the loader
part does not work without an annotation in the subclass. I'm using version 3.2.1.RELEASE of Spring-test
.
Here is a sample projec that shows the bug: