maven 项目 junit步骤。

  1. pom.xml添加对应的jar包

1<dependency> 2 <groupId>junit</groupId> 3 <artifactId>junit</artifactId> 4 <version>4.4</version> 5 <scope>test</scope> 6</dependency> 7 8

2.右键项目 java build path 中add library中添加junit
在这里插入图片描述

3.编写junit测试文件 如:

1package com.sinops.bigscreen.spiders; 2 3import java.util.HashMap; 4import java.util.Map; 5 6import javax.annotation.Resource; 7 8import org.junit.Test; 9import org.junit.runner.RunWith; 10import org.springframework.beans.factory.annotation.Autowired; 11import org.springframework.jdbc.core.JdbcTemplate; 12import org.springframework.test.context.ContextConfiguration; 13import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 15import com.sinops.bigscreen.service.BaiducityService; 16 17 18@RunWith(SpringJUnit4ClassRunner.class)//使用junit4进行测试 19@ContextConfiguration({"classpath*:spring.xml"})//注意添加多个配置文件用逗号分隔" .xml"," .xml"," .xml" 20public class CongestionIndexTest { 21 22 @Resource(name = "baiducityService") 23 private BaiducityService bs; 24 @Autowired 25 private JdbcTemplate jdbcTemplate; 26 @Test 27 public void test() { 28 29 if(jdbcTemplate==null){ 30 System.out.println("呵呵哒"); 31 } 32 bs.CachePut(); 33 CongestionIndex gg=new CongestionIndex(); 34 gg.jdbcTemplate=jdbcTemplate; 35 Map map=new HashMap(); 36 map.put("DISTRICTCODE", "130500"); 37 map.put("DISTRICTNAME", "邢台市"); 38 gg.run(); 39// List<Map> list=new ArrayList(); 40// list.add(gg.getUrl("266",map)); 41// gg.addorupdate(list); 42// 1.2以下为畅通 1.2-1.5 为缓慢 1.5-1.8为拥堵 1.8以上为严重拥堵 43// System.out.println(gg.GetIndexStatus("1.81"));; 44 45 46 } 47 48} 49 50 51

4.然后右键运行即可。大概步骤

代码交流 2021