Search code examples
spring-bootintegration-testingrule

What does SpringClassRule/SpringMethodRule actually do?


In an integration test class I met these lines of code:

    @ClassRule
    public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

    @Rule
    public final SpringMethodRule springMethodRule = new SpringMethodRule();

When I try to navigate to the class (I use Intellij Idea) I get 'Cannot find declaration to go to'. When I try to find usage I get 'No usage found in the project' I am familiar with concept of Rules. But still don't understand what do these two things do. I checked this page: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ no info there.


Solution

  • These aren't Spring Boot specific annotations, rather from the Spring Framework itself and allow use of Spring Contexts etc. without the use of the SpringRunner.

    Javadoc, http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/junit4/rules/SpringClassRule.html

    A concrete example can be found here,

    http://eddumelendez.github.io/blog/2015/08/01/spring-4-2-0-springclassrule-and-springmethodrule/