Java SpringJUnit4ClassRunner 和 SpringRunner 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47446529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between SpringJUnit4ClassRunner and SpringRunner
提问by Humoyun Ahmad
Whenever I see a blog post related to Spring testing I see either of these classes but do not understand the real difference:
每当我看到与 Spring 测试相关的博客文章时,我都会看到这些类中的任何一个,但不明白真正的区别:
@RunWith(SpringRunner.class)
@RunWith(SpringJUnit4ClassRunner.class)
采纳答案by StvnBrkdll
There is no difference, from the javadoc:
与 javadoc 没有区别:
SpringRunner is an alias for the SpringJUnit4ClassRunner.
SpringRunner 是 SpringJUnit4ClassRunner 的别名。
参考:https: //docs.spring.io/spring/docs/4.3.0.RC2_to_4.3.0.RELEASE/Spring%20Framework%204.3.0.RELEASE/org/springframework/test/context/junit4/SpringRunner.html
回答by Joby Wilson Mathews
@RunWith(SpringRunner.class)
tells JUnit to run using Spring's testing support. SpringRunner
is the new name for SpringJUnit4ClassRunner
, it's just a bit easier on the eye.
@RunWith(SpringRunner.class)
告诉 JUnit 使用 Spring 的测试支持运行。SpringRunner
是 的新名称SpringJUnit4ClassRunner
,它看起来更容易一些。
SpringRunner
is only available on spring-test 4.3.
SpringRunner
仅在 spring-test 4.3 上可用。
SpringRunner
class extends SpringJUnit4ClassRunner
.
SpringRunner
类扩展SpringJUnit4ClassRunner
。
Source codeof SpringRunner
is
源代码的SpringRunner
IS
package org.springframework.test.context.junit4;
import org.junit.runners.model.InitializationError;
public final class SpringRunner extends SpringJUnit4ClassRunner {
public SpringRunner(Class<?> clazz) throws InitializationError {
super(clazz);
}
}