Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 964
IKo Avatar asked Jun 29 '17 15:06

IKo


1 Answers

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/

like image 147
Darren Forsythe Avatar answered Nov 16 '22 11:11

Darren Forsythe