@ContextConfiguration注解和@runWith注解作用

@ContextConfiguration注解
1 正常使用
@ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件

1.1 单个文件
@ContextConfiguration(locations="../applicationContext.xml")

@ContextConfiguration(classes = SimpleConfiguration.class)

1.2 多个文件
可用{}

@ContextConfiguration(locations = { "classpath:/spring1.xml", "classpath:/spring2.xml" })

1.3 默认不写
可以根据测试的类名,去找到与之对应的配置文件。
来源: https://www.cnblogs.com/lixuwu/p/6697537.html

@runWith注解作用
@RunWith就是一个运行器

@RunWith(JUnit4.class)就是指用JUnit4来运行

@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境

@RunWith(Suite.class)的话就是一套测试集合

@runWith注解作用
@RunWith就是一个运行器

@RunWith(JUnit4.class)就是指用JUnit4来运行

@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境

@RunWith(Suite.class)的话就是一套测试集合,

@RunWith(SpringJUnit4ClassRunner.class)使用了Spring的SpringJUnit4ClassRunner,以便在测试开始的时候自动创建Spring的应用上下文。其他的想创建spring容器的话,就得子啊web.xml配置classloder。 注解了@RunWith就可以直接使用spring容器,直接使用@Test注解,不用启动spring容器

注:这里SpringRunner 继承了SpringJUnit4ClassRunner,没有扩展任何功能;使用前者,名字简短而已

来源: https://blog.csdn.net/qq_43843725/article/details/97100334

posted @ 2020-08-31 14:46  _Anke  阅读(1027)  评论(0编辑  收藏  举报