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. 5 centos 6.10 三节点安装apache hadoop 2.9.1

    Hadoop 版本: apache hadoop 2.9.1JDK 版本: Oracle JDK1.8集群规划master(1): NN, RM, DN, NM, JHSslave1(2): DN, ...

  2. javascript中json字符串对象转化

    li = [1,2,3,4] s = JSON.stringify(li)  ---转化为字符串 JSON.parse(s) --转化为对象

  3. SSM003/构建Maven单模块项目(二)

    一.Controller基础代码(mooc) 1.UserController.java /** *springmvc1-2:返回jsp页面 * 请求URL: /user/getUserById?us ...

  4. 配置OSPF认证

      按照上图拓扑配置路由器的IP 配置完后测试直连网段连通性 搭建OSPF网络 注意是多区域的配置,R2是ABR 连着area0和area1 并且每个路由器的环回接口IP也要加进去  此时密码以明文方 ...

  5. 剑指Offer编程题(Java实现)——替换空格

    题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 解题思路1 在字符串尾部填充任 ...

  6. JavaScript ES6中export、import与export default的用法和区别

    前言 相信很多人都使用过export.export default.import,然而它们到底有什么区别呢? 在看他们之间的区别之前,我们先来看看它们的用法. ES6 import和export的用法 ...

  7. jQuery 的attr()与css()的区别

    attr是attribute的缩写,意思是标签属性. css是,样式,意思是元素的style样式的 我的理解是: attr是操作元素的   属性 css是操作元素的  style属性 前者可以修改&l ...

  8. SQL SERVER SP命令及实现跨数据库查询

    1.数据库: (1)sp_helpdb:报告有关指定数据库或所有数据库的信息. 例:sp_helpdb   --显示所有数据库信息(名称.大小等) 例:sp_helpdb Recruitment   ...

  9. runtime 理解笔记

    runtime 简称运行时,是系统运行的一种机制,在oc中通过c语言编写一个运行系统库.考进行一些非常底层的操作(oc无法完成的). 1.利用runtime,在程序运行过程中,动态创建一个类(比如KV ...

  10. Java基础学习(4)

    Java基础学习(四) String类 特点:创建后不可再修改,看起来的修改只是创建了新的对象 常用方法 StringBuilder类 目的:解决String类频繁创建对象的问题 常用方法 特点:非线 ...