maven 项目 junit步骤。

    xiaoxiao2022-07-05  163

    pom.xml添加对应的jar包 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.4</version> <scope>test</scope> </dependency>

    2.右键项目 java build path 中add library中添加junit

    3.编写junit测试文件 如:

    package com.sinops.bigscreen.spiders; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.sinops.bigscreen.service.BaiducityService; @RunWith(SpringJUnit4ClassRunner.class)//使用junit4进行测试 @ContextConfiguration({"classpath*:spring.xml"})//注意添加多个配置文件用逗号分隔" .xml"," .xml"," .xml" public class CongestionIndexTest { @Resource(name = "baiducityService") private BaiducityService bs; @Autowired private JdbcTemplate jdbcTemplate; @Test public void test() { if(jdbcTemplate==null){ System.out.println("呵呵哒"); } bs.CachePut(); CongestionIndex gg=new CongestionIndex(); gg.jdbcTemplate=jdbcTemplate; Map map=new HashMap(); map.put("DISTRICTCODE", "130500"); map.put("DISTRICTNAME", "邢台市"); gg.run(); // List<Map> list=new ArrayList(); // list.add(gg.getUrl("266",map)); // gg.addorupdate(list); // 1.2以下为畅通 1.2-1.5 为缓慢 1.5-1.8为拥堵 1.8以上为严重拥堵 // System.out.println(gg.GetIndexStatus("1.81"));; } }

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

    最新回复(0)