使用junit4测试spring项目中service方法

使用junit4测试项目中service方法

 1 import java.util.HashMap;
 2 import java.util.List;
 3 import java.util.Map;
 4 
 5 import javax.annotation.Resource;
 6 
 7 import org.junit.Test;
 8 import org.junit.runner.RunWith;
 9 import org.springframework.test.context.ContextConfiguration;
10 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 
12 import cn.gx.dbc.jgpt.service.StatisDicService;
13 import cn.gx.dbc.model.StatisticsResultDic;
14 
15 @RunWith(SpringJUnit4ClassRunner.class)
16 @ContextConfiguration(locations = "classpath:applicationContext-main.xml")
17 public class ForTest {
18     @Resource
19     private StatisDicService dicService;
20 
21     public StatisDicService getDicService() {
22         return dicService;
23     }
24 
25     public void setDicService(StatisDicService dicService) {
26         this.dicService = dicService;
27     }
28 
29     @Test
30     public void testSpring() {
31         Map<String, String> conditions = new HashMap<String, String>();
32         List<StatisticsResultDic> dicList = dicService.queryDicList(conditions,
33                 null);
34         System.out.println("dicList:" + dicList.size());
35     }
36 }

 记得加入spring-test.jar包

posted @ 2014-08-18 16:38  拔丝苹果皮  阅读(1619)  评论(0编辑  收藏  举报