一、创建基础类。

package com.tree.autotest;

import org.junit.Before;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContextManager;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; /**
* 规则包:
* 规则编码:
* 规则名称:
* 规则条件:
* <p>
* Created by zhf2015 on 16/8/1.
*/
//@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring-context.xml"})
@Configuration
public class BaseJunit4Test extends AbstractJUnit4SpringContextTests { protected TestContextManager testContextManager;
@Before
public void setUpContext() throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.testContextManager.prepareTestInstance(this);
} } 二、创建测试类,继承基础类。
package com.tree.autotest.testcase.BillDetailTypeService;

import com.datatrees.basisdata.bankbill.model.Bill;
import com.datatrees.basisdata.bankbill.service.BillService;
import com.tree.autotest.BaseJunit4Test;
import com.tree.autotest.commons.CommonUtil_2;
import com.tree.autotest.commons.TestCase;
import com.tree.autotest.jdbc.DBIdConstant;
import com.tree.autotest.jdbc.ManagedSqlUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map; /**
* Created by lyh on 17/2/13.
*/
@RunWith(value=Parameterized.class)
public class TestSelectListByUserId2 extends BaseJunit4Test{
// ApplicationContext factory=new ClassPathXmlApplicationContext("classpath:/spring-context.xml");
@Autowired
private BillService billService;
// private BillService billService = (BillService)factory.getBean("billService");
private static final Logger logger = LoggerFactory.getLogger(TestSelectListByUserId2.class); private boolean handleOk;
private String insertSql1;
private static String excel;
private static Map allCases;
private Integer testUser; @Parameterized.Parameters
public static Collection<Integer[]> getTestParameters(){ List<Integer[]> list = new ArrayList<Integer[]>();
list.add(new Integer[]{2000998248}); //expected,valueOne,valueTwo
list.add(new Integer[]{2000020021});
list.add(new Integer[]{2001999335});
String st=list.toString();
System.out.println("list值:" + st); return list; }
public TestSelectListByUserId2(Integer userid){
this.testUser = userid;
} @Before
public void setUp() throws SQLException {
//获取excel用例列表
excel = "src/main/resources/case/BillService/TestSelectListByUserId.xlsx";
allCases = CommonUtil_2.getAllCases(excel);
System.out.println("setUp 执行");
// //获取用户ID
TestCase testcase = CommonUtil_2.getTestCaseBean(allCases, "case1", "case1-1");
testUser =Integer.valueOf(testcase.param1);
//获取SQL
insertSql1 = testcase.stepSql;
//删除,添加数据
handleOk &= deleteData(testUser);
handleOk &= ManagedSqlUtil.insertBySql(insertSql1, DBIdConstant.MySql_Basisdata_ID); } @Test
public void test_case_1() throws Exception {
//++++++++++++++实际值+++++++++++++
List<Bill> actual_list =
billService.selectListByUserId(testUser);
System.out.println("testUser值:"+testUser);
//++++++++++++++验证+++++++++++++
Assert.assertNotNull("测试失败",actual_list);
for(int i=0;i<actual_list.size();i++) {
Assert.assertEquals("测试失败",actual_list.get(i).getUserId(),testUser);
}
System.out.println("actual_list的size:"+actual_list.size());
} @After
public void tearDown() { deleteData(testUser);
System.out.println("tearDown 执行");
} //定义数据清理
public boolean deleteData(Integer userId) {
String deleteSql1 = "delete from t_bill where UserId="+userId+";";
handleOk &= ManagedSqlUtil.deleteBySql(deleteSql1, DBIdConstant.MySql_Basisdata_ID);
return handleOk;
}
} 三、配置文件和数据文件和上一篇文章一致。

最新文章

  1. PHP中float变量转换为int时,结果有误的问题!
  2. PythonOCC 3D图形库学习—创建立方体模型
  3. OpenGL的glClearColor和glClear改变背景颜色
  4. csipsimple 下载地址
  5. c# 学习笔记(二)
  6. poj2299--B - Ultra-QuickSort(线段树,离散化)
  7. ACM经典算法之字符串处理:字符串替换
  8. SQL性能优化的几点建议
  9. Redis进阶实践之十九 Redis如何使用lua脚本
  10. JavaScript数据结构与算法(八) 集合(ECMAScript 6中定义的类似的Set类)
  11. pycharm的list的应用
  12. RabbitMQ学习笔记(三) 发布与订阅
  13. Spring boot 的自动配置
  14. VS2013中编译openssl的步骤和使用设置
  15. Linux 特殊字符_008
  16. Django学习手册 - 正则URL路由配置/路由分发
  17. [问题解决]RedHat7更换CentOS7的yum源时踩过的坑
  18. python读取配置文件&amp;&amp;简单封装
  19. Dapper使用总结
  20. JS基础----&gt;javascript的基础(二)

热门文章

  1. es6字符串模板总结
  2. keycloack docker 本地运行
  3. 【ASP.NET MVC】 路由机制:命名路由
  4. HDU 4348.To the moon SPOJ - TTM To the moon -可持久化线段树(带修改在线区间更新(增减)、区间求和、查询历史版本、回退到历史版本、延时标记不下放(空间优化))
  5. hihoCoder #1831 : 80 Days-RMQ (ACM/ICPC 2018亚洲区预选赛北京赛站网络赛)
  6. python3 2017.3.19
  7. SpringMVC中为什么要配置Listener和Servlet
  8. class getResourceAsStream 和 classloader getResourceAsStream获取资源的不同
  9. Luogu P2590 树的统计(树链剖分+线段树)
  10. Codeforces Round #294 (Div. 2) A and B and Lecture Rooms(LCA 倍增)