DAO层单元测试编码和问题排查

SecKillDaoTest .java(注意接口参数使用注解@Parm(“parameter”))

package org.secKill.dao;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.secKill.entity.SecKill;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

import java.util.Date;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Created by 谭雪娇 on 2017/5/4.
 * 配置spring和junit整合,junit启动时加载springIOC容器
 * spring-test,junit
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring/spring-dao.xml"})
public class SecKillDaoTest {
//注入Dao实现类依赖
    @Resource
    private SecKillDao secKillDao;
    @Test
    public void testQueryById() throws Exception {
        long id=1000;
        SecKill secKill=secKillDao.queryById(id);
        System.out.println(secKill.getName());
        System.out.println(secKill);

}
//100元秒杀诺基亚
//   SecKill{secKillId=1000, name='100元秒杀诺基亚', number=10000, startTime=Fri Feb 17 12:02:05 CST 2017,
// endTime=Sat Dec 21 00:00:00 CST 2019, createTime=Wed Dec 21 00:00:00 CST 2016}

    @Test
    public void testQueryAll() throws Exception {
//     java没有保存形参的记录:queryAll(int off,int,limit)->queryAll(arg0,arg1)
        List<SecKill> secKills=secKillDao.queryAll(0,100);
        for(SecKill secKill:secKills){
            System.out.println(secKill);
        }
    }
//        SecKill{secKillId=1004, name='1400元秒杀魅族4', number=1099, startTime=Fri Feb 17 12:02:28 CST 2017, endTime=Sat Feb 17 11:48:00 CST 2018, createTime=Fri Feb 17 11:48:00 CST 2017}
//        SecKill{secKillId=1000, name='100元秒杀诺基亚', number=10000, startTime=Fri Feb 17 12:02:05 CST 2017, endTime=Sat Dec 21 00:00:00 CST 2019, createTime=Wed Dec 21 00:00:00 CST 2016}
//        SecKill{secKillId=1003, name='1600元秒杀小米4', number=1200, startTime=Fri Feb 17 11:47:47 CST 2017, endTime=Sat Jul 23 00:00:00 CST 2016, createTime=Sat Jul 23 00:00:00 CST 2016}
//        SecKill{secKillId=1002, name='1000元秒杀ipad1', number=3500, startTime=Fri Feb 17 11:47:41 CST 2017, endTime=Thu May 12 00:00:00 CST 2016, createTime=Thu May 12 00:00:00 CST 2016}
//        SecKill{secKillId=1001, name='5000元秒杀iphone7', number=1700, startTime=Fri Feb 17 11:47:36 CST 2017, endTime=Mon Apr 11 00:00:00 CST 2016, createTime=Mon Apr 11 00:00:00 CST 2016}
//        SecKill{secKillId=1005, name='1400元秒杀小米3', number=1100, startTime=Fri Feb 17 11:48:23 CST 2017, endTime=Thu Jan 21 00:00:00 CST 2016, createTime=Thu Jan 21 00:00:00 CST 2016}

    @Test
    public void testReduceNumber() throws Exception {
        Date KillDate=new Date();
        int updateCount=secKillDao.reduceNumber(1000L,KillDate);
        System.out.println("updateCount:"+updateCount);

}

//updateCount:1
}

testInsertSuccessKilled.java

package org.secKill.dao;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.secKill.entity.SuccessKilled;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

import static org.junit.Assert.*;

/**
 * Created by 谭雪娇 on 2017/5/4.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/spring-dao.xml")
public class SuccessKilledDaoTest {
    @Resource
    private SuccessKilledDao successKilledDao;
    @Test
    public void testInsertSuccessKilled() throws Exception {
        long id=1000L;
        long number=13535353535L;
        int insertCount=successKilledDao.insertSuccessKilled(id,number);
        System.out.println("insertCount:"+insertCount);
    }
    //第一次执行:insertCount:1
    //第二次执行:insertCount:0
    @Test
    public void testQueryByIdWithSecKill() throws Exception {
        long id=1000L;
        long number=13535353535L;
        SuccessKilled successKilled=successKilledDao.queryByIdWithSecKill(id,number);
        System.out.println(successKilled);
        System.out.println(successKilled.getSecKill());
    }
    //SuccessKilled{secKillId=1000, userPhone=13535353535, state=0, createTime=Thu May 04 19:40:19 CST 2017}
    //SecKill{secKillId=1000, name='100元秒杀诺基亚', number=9999, startTime=Thu May 04 19:14:21 CST 2017, endTime=Sat Dec 21 00:00:00 CST 2019, createTime=Wed Dec 21 00:00:00 CST 2016}

}

DAO层单元测试编码和问题排查的更多相关文章

  1. 使用springboot实现一个简单的restful crud——02、dao层单元测试,测试从数据库取数据

    接着上一篇,上一篇我们创建了项目.创建了实体类,以及创建了数据库数据.这一篇就写一下Dao层,以及对Dao层进行单元测试,看下能否成功操作数据库数据. Dao EmpDao package com.j ...

  2. dao层单元测试报错CONDITIONS EVALUATION REPORT

    0 环境 系统:win10 编辑器:IDEA 1 正文 1.1 起因 在controller层测试 测试url时没问题的 但是我单元测试就报错 1.2 排查 因为controller层 springb ...

  3. 使用Unitils测试DAO层

    Spring 的测试框架为我们提供一个强大的测试环境,解决日常单元测试中遇到的大部分测试难题:如运行多个测试用例和测试方法时,Spring上下文只需创建一次:数据库现场不受破坏:方便手工指定Sprin ...

  4. 01 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目之业务分析与DAO层

    作者:nnngu 项目源代码:https://github.com/nnngu/nguSeckill 这是一个整合IDEA+Maven+SSM框架的高并发的商品秒杀项目.我们将分为以下几篇文章来进行详 ...

  5. dbunit进行DAO层Excel单元测试

    DAO层测试难点 可重复性,每次运行单元测试,得到的数据是重复的 独立性,测试数据与实际数据相互独立 数据库中脏数据预处理 不能给数据库中数据带来变化 DAO层测试方法 使用内存数据库,如H2.优点: ...

  6. 基于dbunit进行mybatis DAO层Excel单元测试

    DAO层测试难点 可重复性,每次运行单元测试,得到的数据是重复的 独立性,测试数据与实际数据相互独立 数据库中脏数据预处理 不能给数据库中数据带来变化 DAO层测试方法 使用内存数据库,如H2.优点: ...

  7. Junit结合Spring对Dao层进行单元测试

    关于单元测试,上一次就简单的概念和Mock基础做了,参考:http://60.174.249.204:8888/in/modules/article/view.article.php/74 实际开发过 ...

  8. spring boot 集成 mybatis 单元测试Dao层 控制台报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    最近帮同学做毕业程序,采用后端spring boot + mybatis + H2,将框架搭好进行各层的单元测试时,在dao层就出现了错,如图 于是在网上找各种资料,有的说是xml文件和接口没有一一对 ...

  9. mybatis的dao层和service层的编码设计的配置

    /** 书写pojo类------>dao接口------>resources下建立同路径的dao.xml------>配置applicationContext.xml文件 **/ ...

随机推荐

  1. 几个模拟OLE事件注册、调用的宏

    最近遇到一个要求,将原来的OCX控件,替换成直接的DLL调用. 遇到OLE的事件回调,写了三个宏,用于简化代码 #define OLE_ENVENT_IN_CLASS_ONE(event_name, ...

  2. 【ABAP系列】SAP VA02修改销售订单的BAPI举例

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP VA02修改销售订单的B ...

  3. oracle linux 7使用udev绑盘操作

    参考:Oracle Linux 7: Udev rule for ASM Cannot Place the ASM Disk in a Directory under /dev (Doc ID 221 ...

  4. oracle--表类型

  5. 不用找了,300 分钟帮你搞定 Spring Cloud!

    最近几年,微服务架构一跃成为 IT 领域炙手可热的话题,大量一线互联网公司因为庞大的业务体量和业务需求,纷纷投入了微服务架构的建设中,像阿里巴巴.百度.美团等大厂,很早就已经开始了微服务的实践和应用. ...

  6. JDK11 | 第二篇 : JShell 工具

    文章首发于公众号<程序员果果> 地址 : https://mp.weixin.qq.com/s/saHBSTo4OjsIIqv_ixigjg 一.简介 Java Shell工具是JDK1. ...

  7. shutdown的几种方法和利弊

    1.shutdown normal      正常方式关闭数据库. 2.shutdown immediate      立即方式关闭数据库.      在SVRMGRL中执行shutdown imme ...

  8. js页面加载的几种方式的速度: window.onload、 $(window).load、 $(function(){})、 $(document).ready(function () {})、onload=‘asd()’

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. (五:NIO系列) Reactor模式

    出处:Reactor模式 本文目录 1. 为什么是Reactor模式 2. Reactor模式简介 3. 多线程IO的致命缺陷 4. 单线程Reactor模型 4.1. 什么是单线程Reactor呢? ...

  10. Log4Net 之将自定义属性记录到文件中 (三)

    原文:Log4Net 之将自定义属性记录到文件中 (三) 即解决了将自定义属性记录到数据库之后.一个新的想法冒了出来,自定义属性同样也能记录到文件中吗?答案是肯定的,因为Log4Net既然已经考虑到了 ...