zoukankan      html  css  js  c++  java
  • SpringBoot整合junit

    SpringBoot整合junit

    主要分为4步

    1.  添加依赖
    2. 创建测试类
    3. 在测试类上添加注解
    4. 在测试类注入测试对象

    1:导入依赖包

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>

    2:创建测试类

    3:在测试类上添加注解并注入测试对象

    测试类上注解:

    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = Springbootdemo1Application.class)
    package com.offcn.springbootdemo1;

    import com.offcn.springbootdemo1.mapper.UUserMapper;
    import com.offcn.springbootdemo1.pojo.UUser;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;

    import javax.annotation.Resource;
    import java.util.List;

    //添加整合junit注解
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = Springbootdemo1Application.class)
    public class AppTest {
       //注入Mapper对象,用来获取List<UUser>集合

    @Resource
    private UUserMapper userMapper;
    @Test
    public void TestMethod(){
    List<UUser> uUsers = userMapper.selectUUser();
    for (UUser uUser : uUsers) {
    System.out.println(uUser);
    }
    }
    }
  • 相关阅读:
    09.安装Collabora Online服务
    08.nextcloud搭建
    07.安装及使用gitlub
    winmerge vs2010
    C#中时间计算汇总
    JS正则表达式大全 转
    js 验证正则
    js验证大全
    CSC 命令编译cs文件
    网站PV、UV以及查看方法(转)
  • 原文地址:https://www.cnblogs.com/wangju/p/11801480.html
Copyright © 2011-2022 走看看