【问题标题】:What does SpringClassRule/SpringMethodRule actually do?SpringClassRule/SpringMethodRule 实际上做了什么?
【发布时间】:2017-06-29 15:32:06
【问题描述】:

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

    @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/ 那里没有信息。

【问题讨论】:

  • 除了@darren-forsythe 在最新版本的 Spring Boot 中所说的,@RunWith(SpringJUnit4ClassRunner.class) 已被删除,您应该使用@RunWith(SpringRunner.class)

标签: spring-boot integration-testing rule


【解决方案1】:

这些不是 Spring Boot 特定的注释,而是来自 Spring 框架本身,并且允许使用 Spring 上下文等而不使用 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/

【讨论】:

    猜你喜欢
    • 2013-06-02
    • 2020-11-21
    • 2015-02-26
    • 2017-06-29
    • 2013-06-13
    • 2021-10-25
    • 2011-08-12
    • 1970-01-01
    • 2010-11-27
    相关资源
    最近更新 更多