SpringBoot的单元测试

package io.renren;

import io.renren.common.utils.Query;
import io.renren.modules.sys.entity.AlarmRecordEntity;
import io.renren.modules.sys.service.AlarmRecordService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Service层的测试类
 *
 * @Author: Connie
 * @Date: 2018/4/12 11:40
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class AlarmRecordSerTest {

    @Autowired
    private AlarmRecordService alarmRecordService;


    /**
     * 查询测试
     */
    @Test
    public void getAlarmRecordList() {

        Map<String, Object> map = new HashMap<>();
        map.put("page", 1);
        map.put("limit", 5);
        Query query = new Query(map);
        List<AlarmRecordEntity> alarmRecordList = alarmRecordService.getAlarmRecordList(query);

        for (AlarmRecordEntity a : alarmRecordList) {
            System.out.println(a.getModuleInfo());
        }
    }


    /**
     * 添加测试
     */
    @Test
    public void saveAlarmRecord() {

        AlarmRecordEntity a = new AlarmRecordEntity();
        a.setAlarmTypeId(1);
        a.setDescribeDetail("测试添加详情");

//        Date date = Date.valueOf("2010-01-01 12:12:12");
//        a.setEvenBegintime(new Timestamp(date.getTime()));
        a.setModuleInfo("测试模块");
        a.setRemark("测试备注");
        a.setResult("测试结果");

        alarmRecordService.save(a);
        System.out.println("添加成功!");
    }

    /**
     * 修改测试
     */
    @Test
    public void updateAlarmRecord() {
        AlarmRecordEntity a = new AlarmRecordEntity();
        a.setId(12);
        a.setAlarmTypeId(1);
        a.setDescribeDetail("测试添加详情1");

//        Date date = Date.valueOf("2010-01-01 12:12:12");
//        a.setEvenBegintime(new Timestamp(date.getTime()));
        a.setModuleInfo("测试模块1");
        a.setRemark("测试备注1");
        a.setResult("测试结果1");

        alarmRecordService.update(a);
        System.out.println("修改成功!");
    }


    /**
     * 删除测试
     */
    @Test
    public void deleteAlarmRecord() {
        String[] strs = {"12", "9"};
        Long[] ids = new Long[strs.length];

        for (int i = 0; i < strs.length; i++) {
            ids[i] = Long.parseLong(strs[i]);
        }
        alarmRecordService.deleteBatch(ids);
    }


}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值