Spring框架整合JUnit单元测试

1. 为了简化了JUnit的测试,使用Spring框架也可以整合测试
2. 具体步骤
    * 要求:必须先有JUnit的环境(即已经导入了JUnit4的开发环境)!!

    * 步骤一:在程序中引入:spring-test.jar
    * 步骤二:在具体的测试类上添加注解
        @RunWith(SpringJUnit4ClassRunner.class)
        @ContextConfiguration("classpath:applicationContext.xml")//这两句注解就相当于之前的加载核心配置文件语句
        public class SpringDemo1 {

            @Resource(name="userService")
            private UserService userService;

            @Test
            public void demo2(){
                userService.save();
            }
        }
原文地址:https://www.cnblogs.com/wyhluckdog/p/10129888.html