spring整合Junit方法,支持注解

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();
    }

}

 

  

posted @ 2016-01-15 15:01  mr_level  阅读(1000)  评论(0编辑  收藏  举报