I have some test that need Spring context to run:
@SpringBootTest
@ContextConfiguration(classes = Application.class)
@Transactional
@ActiveProfiles("test")
@Rollback
@RunWith(SpringRunner.class)
public class SomeTest() {
@Test
public void test() {
...
}
}
I have created custom annotation for test:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@SpringBootTest
@ContextConfiguration(classes = Application.class)
@Transactional
@ActiveProfiles("test")
@Rollback
@RunWith(SpringRunner.class)
public @interface DBTest {
}
Now - when i use @DBTest annotation on my test:
@DBTest
public class SomeTest {
@Test
public void test() {
...
}
}
In this case Spring context was not started. How can I start that?
Try putting @RunWith(SpringRunner.class) in your SomeTest class annotations. In order to apply the annotations you need spring to analyse them. But since your RunWith is not on your class, jUnit framework doesn't start spring, which, in turn, doesn't analyse the annotations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With