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

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.SpringJUnit4Cla***unner;

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(SpringJUnit4Cla***unner.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.SpringJUnit4Cla***unner;

import javax.annotation.Resource;

import static org.junit.Assert.*;

/**
 * Created by 谭雪娇 on 2017/5/4.
 */
@RunWith(SpringJUnit4Cla***unner.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}

}

 

上一篇:SVN:自动加锁


下一篇:痞子衡嵌入式:开启NXP-MCUBootUtility工具的HAB签名功能 - CST(中英双语)