Spring中使用@RunWith整合的测试注解

Spring中使用@RunWith整合的测试注解

大家比较熟悉下面的代码:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
  • @RunWith就是一个运行器

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

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

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

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

  • 单个文件
    @ContextConfiguration(Locations="classpath:applicationContext.xml")
    @ContextConfiguration(classes = SimpleConfiguration.class)

  • 多个文件时,可用
    @ContextConfiguration(locations = { "classpath:spring1.xml", "classpath:spring2.xml" })

发布了74 篇原创文章 · 获赞 24 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/STUDENTstudent123/article/details/100139405
今日推荐