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. Android studio R文件丢失或错误解决方法

    android studio中有时引用资源会出现R文件丢失或报错,大多数情况下是由于引入资源时R文件没有及时更新造成的 (在代码没有错误或资源引用没有错误的前提下) 注意:资源文件的文件名必须小写,即 ...

  2. FCC-学习笔记 Spinal Tap Case

    FCC-学习笔记   Spinal Tap Case 1>最近在学习和练习FCC的题目.这个真的比较的好,推荐给大家. 2>中文版的地址:https://www.freecodecamp. ...

  3. Spring登录实例

    Spring登录实例 项目结构 首先看一下整个项目的目录结构,如下: 导入Jar包 工欲善必先利其器,导入一下Jar包 配置文件 web.xml 配置 web.xml配置文件,如下: xmlns:xs ...

  4. Linux signal与定时器

    1. signal sighandler_t signal(int signum, sighandler_t handler); signum:是一个信号.除了SIGKILL和SIGSTOP外的任何一 ...

  5. ios--NavigationViewController跳转、返回传值

      使用NavigationViewController进行页面跳转时,应该使用pushViewController方法来跳转至下一页面,这样的话,下一页面同样在NavigationViewContr ...

  6. HDFS常用API操作 和 HDFS的I/O流操作

    前置操作 创建maven工程,修改pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...

  7. Error: EACCES: permission denied, mkdir

    今天在全局安装飞冰的时候,出现标题的错误 想到是权限不够的问题,其实飞冰官网也有解决的办法,就是更改npm的默认路径.我之前就是用了更改默认路径的方法,然后后来又恢复了默认路径,所以还是用默认路径加权 ...

  8. 笔记8:Linux知识

    linux学习笔记 1 Linux介绍 1.1 基本知识 应用领域:服务器使用 LAMP(Linux + Apache + MySQL + PHP)或 LNMP(Linux + Nginx+ MySQ ...

  9. 出现org.springframework.beans.factory.NoSuchBeanDefinitionException 的解决思路

    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: privat ...

  10. 201871010109-胡欢欢《面向对象程序设计(java)》第八周学习总结

    博文正文开头:(2分) 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/ ...