Skip to main content
 首页 » 编程设计

spring-boot之SpringClassRule/SpringMethodRule 实际上做了什么

2024年05月29日39softidea

在集成测试类中,我遇到了这些代码行:

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

当我尝试导航到该类(我使用 Intellij Idea)时,我收到“找不到要访问的声明”。当我尝试查找用法时,我收到“项目中未找到用法” 我熟悉规则的概念。但还是不明白这两个东西是做什么用的。 我检查了此页面:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 那里没有信息。

请您参考如下方法:

这些不是 Spring Boot 特定的注释,而是来自 Spring 框架本身,并且允许使用 Spring Context 等,而无需使用 SpringRunner

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

具体的例子可以在这里找到,

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