I have a large number of test cases that work with Spring Junit Support with the following annotations on each test.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring/applicationContext.xml")
@TransactionConfiguration(transactionManager="transactionManager")
@Transactional
@ActiveProfiles("test")
Instead of putting all of these annotations into each test class, I want to create a custom annotation and use it.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring/applicationContext.xml")
@TransactionConfiguration(transactionManager="transactionManager")
@Transactional
@ActiveProfiles("test")
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface SpringJUnit4TestConfig {
}
But when I use this custom Spring annotation, injection does not occur at all.
@SpringJUnit4TestConfig
public class UserServiceTest
{
}
What am I missing here?
PS: But JUnit @RunWith and Spring @Transactional, @ContextConfiguration all have @ Inherited..So, I thought it should work. But for now, I get it through work. Created a class Based Abstract and put all these annotations on it and test cases that extend this base class.