Spring - JUnit整合测试
作者:互联网
1、导包:test.jar
2、使用@RunWith注解创建spring容器 - @RunWith(SpringJUnit4ClassRunner.class)
3、使用@ContextConfiguration读取spring配置文件 - @ContextConfiguration("classpath:applicationContext.xml")
4、使用@Resource获取已装配bean的对象
package com.sikiedu.test; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.sikiedu.service.UserService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml") public class AopTest { // 将名为userService的对象注入到UserService中 @Resource(name = "userService") private UserService us; @Test public void test2() { us.delete(); } }
标签:RunWith,Spring,ContextConfiguration,测试,org,test,import,JUnit,UserService 来源: https://www.cnblogs.com/Dm920/p/12076593.html