使用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包

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-06-19
  • 2022-12-23
  • 2021-10-27
  • 2021-10-19
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2022-02-03
  • 2021-08-22
  • 2022-12-23
  • 2022-02-05
相关资源
相似解决方案