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);
}
}
}

SpringBoot整合junit的更多相关文章

  1. Springboot的日志管理&Springboot整合Junit测试&Springboot中AOP的使用

    ==============Springboot的日志管理============= springboot无需引入日志的包,springboot默认已经依赖了slf4j.logback.log4j等日 ...

  2. SpringBoot学习16:springboot整合junit单元测试

    1.创建maven项目,修改pom.xml文件 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springfram ...

  3. Springboot整合Junit单元测试

    1.在pom.xml中添加junit环境的依赖 <dependency> <groupId>org.springframework.boot</groupId> & ...

  4. springBoot整合Mybatis,Junit

    笔记源码:https://gitee.com/ytfs-dtx/SpringBoot 整合Mybatis SpringBoot的版本:2.2.5.RELEASE Mybatis版本:mybatis-s ...

  5. springBoot第二种配置文件yaml书写方式及读取数据、整合myBatis和整合junit

    一.yaml文件格式:key-value形式:可以表示对象 集合 1.语法:key:value 冒号后面必须跟一个空格再写value值 key1: key2: key3:value 2.属性取值:a. ...

  6. SpringBoot整合Netty并使用Protobuf进行数据传输(附工程)

    前言 本篇文章主要介绍的是SpringBoot整合Netty以及使用Protobuf进行数据传输的相关内容.Protobuf会简单的介绍下用法,至于Netty在之前的文章中已经简单的介绍过了,这里就不 ...

  7. Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ

    集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...

  8. java操作mongodb & springboot整合mongodb

    简单的研究原生API操作MongoDB以及封装的工具类操作,最后也会研究整合spring之后作为dao层的完整的操作. 1.原生的API操作 pom.xml <!-- https://mvnre ...

  9. SpringBoot系列十:SpringBoot整合Redis

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合 Redis 2.背景 Redis 的数据库的整合在 java 里面提供的官方工具包:jed ...

随机推荐

  1. java servlet 初学笔记

    1. 页面HTML标签中的中文乱码 在 doGet 或者 doPost 等方法内的第一行添加: response.setCharacterEncoding("gbk"); 2. 避 ...

  2. java--Proreties

    Prorerties /* * Properties,内存与文件信息交互 * 表示了一个持久的属性集 * * 构造方法: * Properties() * * */ //简单使用 创建,添加,遍历, ...

  3. 【Web安全入门】三个技巧教你玩转XSS漏洞

    XSS漏洞是Web应用程序中最常见的漏洞之一,想要入门Web安全的小伙伴,这个知识点是必学的. i春秋官网中有很多关于XSS漏洞的课程,新手小白可以去官网看课学习. 学习地址:https://www. ...

  4. 【Java】简体中文、繁体中文转换

    项目中用到繁体中文语言适配,目前已经有开源的框架可以将简体中文转换成繁体中文,在此基础上封装了一个工具类,可以直接将简体中文的strings.xml转换成繁体中文的strings.xml. 引用Jar ...

  5. Jmeter参数化、检查点、集合点教程

    在使用Jemeter做压力测试的时候,往往需要参数化用户名,密码以到达到多用户使用不同的用户名密码登录的目的,这个时候我们就可以使用参数化登录. 一.badboy录制需要的脚本.也可以用fiddler ...

  6. secruity

    security3.x <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns=& ...

  7. JavaScript深入浅出第5课:Chrome是如何成功的?

    摘要: Chrome改变世界. <JavaScript深入浅出>系列: JavaScript深入浅出第1课:箭头函数中的this究竟是什么鬼? JavaScript深入浅出第2课:函数是一 ...

  8. Linux强制关掉其他ssh登录的用户

    Linux强制关掉其他ssh登录的用户 首先 用who命令查看登录的iproot pts/0 162.16.16.155 14:30 0.00s 0.07s 0.05s wroot pts/1 162 ...

  9. Ubuntu14 关机重启、版本、网络、防火墙

    关机.重启: 立即关机:halt.poweroff.shutdown -h now 延迟关机:shutdown -h 10  十分钟后关机 立即重启:reboot.shutdown -r now 延迟 ...

  10. typeof运算对于null会返回“Object"

    您也许会问,为什么 typeof 运算符对于 null 值会返回 "Object".这实际上是 JavaScript 最初实现中的一个错误,然后被 ECMAScript 沿用了.现 ...