Spring与Junit测试整合

一、引入spring测试包:text包

二、@RunWith:指定spring对junit提供的一个运行器

  @ContextConfiguration:  locations指定spring配置文件位置

 1 @RunWith(SpringJUnit4ClassRunner.class)
 2 @ContextConfiguration(locations={"classpath:ApplicationContext.xml"})
 3 public class TestSpring1 {
 4     @Autowired
 5     private PersonService ps;
 6     @Test
 7     public void test1(){
 8         ps.savePerson();
 9     }
10 }
原文地址:https://www.cnblogs.com/cat-fish6/p/8698499.html