Junit5 + SpringBoot

package com.jdrx.wt;

import com.google.common.collect.Lists;
import com.jdrx.wt.beans.dto.AddSectionDTO;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;

/**
 * @Author: liaosijun
 * @Time: 2020/8/13 17:09
 */
@SpringBootTest
@ExtendWith(SpringExtension.class)
class AppSurveyServiceTest {

    @Autowired
    AppSurveyService appSurveyService;

    static List<AddSectionDTO> list = Lists.newArrayList();

    @BeforeAll
    static void init(){

        AddSectionDTO a = new AddSectionDTO();
        a.setCategory("雨水");
        a.setCheckResultId(10L);
        a.setDiam("87");
        a.setFinishCode("a334");
        a.setMaterial(3L);
        a.setSectionId(112L);
        a.setSectionLength(34.90d);
        a.setStartCode("a332");
        list.add(a);

        AddSectionDTO b = new AddSectionDTO();
        b.setCategory("无水");
        b.setCheckResultId(10L);
        b.setDiam("89");
        b.setFinishCode("a334");
        b.setMaterial(3L);
        b.setSectionId(112L);
        b.setSectionLength(34.90d);
        b.setStartCode("a332");
        b.setId(5L);
        list.add(b);
    }
    @org.junit.jupiter.api.Test
    void batchInsertSection() {
        Assert.assertEquals(2, appSurveyService.batchInsertSection(list));
    }

    @org.junit.jupiter.api.Test
    void batchUpdateSection() {
        Assert.assertEquals(1, appSurveyService.batchUpdateSection(list));
    }
}

备注: 测试类需要和springboot启动类同一级目录。

posted @ 2020-08-13 20:05  正宗老菜鸟  阅读(1311)  评论(0编辑  收藏  举报