问题描述
此注释的作用是什么?
我什么时候要使用它?
我什么时候不想使用它?
What does this annotation do?
When would I want to use it?
When would I not want to use it?
@RunWith(SpringJUnit4ClassRunner.class)
当我使用Google时,我可以找到更多用法,而对于该注释应该传达给我什么或何时/为什么使用它,找不到101的解释?
I can find more usages of this when I Google and do not find a 101 explanation as to what this annotation is supposed to communicate to me or when/why I would use it?
推荐答案
注释用于配置需要Spring依赖注入的单元测试.
The annotation is used to configure a unit test that required Spring's dependency injection.
来自 Spring参考-10.单元测试 :
为了使单元测试运行批处理作业,框架必须加载作业的ApplicationContext.使用两个注释来触发此操作:
In order for the unit test to run a batch job, the framework must load the job's ApplicationContext. Two annotations are used to trigger this:
@RunWith(SpringJUnit4ClassRunner.class):指示该类应使用Spring的JUnit工具.
@RunWith(SpringJUnit4ClassRunner.class): Indicates that the class should use Spring's JUnit facilities.
@ContextConfiguration(locations = {...}):指示哪些XML文件包含ApplicationContext.
@ContextConfiguration(locations = {...}): Indicates which XML files contain the ApplicationContext.
这篇关于这是做什么的:@RunWith(SpringJUnit4ClassRunner.class)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!