1, 导入 spring-test-3.2.0.RELEASE.jar
2.添加依赖包 项目右键单击BuildPath>AddLibrary>JUnit 选JUnit4 完成.
3.创建测试类
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.level.service.TestService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="classpath:beans.xml")//加载spring容器配置文件 public class TestJUnit { @Autowired TestService testService; @Test public void test1(){ testService.save(); } }
原文:http://www.cnblogs.com/mr-level/p/5133354.html