1.在pom.xml下添加Junit依赖:

<!--添加junit环境的jar包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

2.创建测试类:

/**
* Created by Administrator on 2019/2/14.
*/ import com.zoctan.api.Application;
import com.zoctan.api.dto.AccountWithRole;
import com.zoctan.api.service.AccountService;
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.SpringJUnit4ClassRunner; import java.util.List; /**
* SpringBoot 测试类
*
* @RunWith:启动器 SpringJUnit4ClassRunner.class:让 junit 与 spring 环境进行整合
* @SpringBootTest(classes={App.class}) 1, 当前类为 springBoot 的测试类
* @SpringBootTest(classes={App.class}) 2, 加载 SpringBoot 启动类。启动springBoot
* junit 与 spring 整合@Contextconfiguartion("classpath:applicationContext.xml")
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {Application.class})
public class AccountTest { @Autowired
private AccountService accountService; //要注入的bean @Test
public void list(){
     //调用测试的方法
final List<AccountWithRole> list = accountService.listAllWithRole();
System.out.println(list);
for(AccountWithRole role : list){
System.out.println(role.getRoleName());
}
} }

SpringBoot集成Junit的更多相关文章

  1. springboot集成junit测试与javamail测试遇到的问题

    1.springboot如何集成junit测试? 导入junit的jar包 使用下面注解: @RunWith()关于这个的解释看下这两篇文章: http://www.imooc.com/qadetai ...

  2. SpringBoot 集成JUnit

    项目太大,不好直接测整个项目,一般都是切割成多个单元,单独测试,即单元测试. 直接在原项目上测试,会把项目改得乱七八糟的,一般是单独写测试代码. 进行单元测试,这就需要集成JUnit. (1)在pom ...

  3. springboot集成mybatis(二)

    上篇文章<springboot集成mybatis(一)>介绍了SpringBoot集成MyBatis注解版.本文还是使用上篇中的案例,咱们换个姿势来一遍^_^ 二.MyBatis配置版(X ...

  4. springboot集成mybatis(一)

    MyBatis简介 MyBatis本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation迁移到了google code,并且改名为MyB ...

  5. springboot集成redis(mybatis、分布式session)

    安装Redis请参考:<CentOS快速安装Redis> 一.springboot集成redis并实现DB与缓存同步 1.添加redis及数据库相关依赖(pom.xml) <depe ...

  6. Windows环境下springboot集成redis的安装与使用

    一,redis安装 首先我们需要下载Windows版本的redis压缩包地址如下: https://github.com/MicrosoftArchive/redis/releases 连接打开后如下 ...

  7. springboot集成elasticsearch

    在基础阶段学习ES一般是首先是 安装ES后借助 Kibana 来进行CURD 了解ES的使用: 在进阶阶段可以需要学习ES的底层原理,如何通过Version来实现乐观锁保证ES不出问题等核心原理: 第 ...

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

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

  9. SpringBoot集成Mybatis并具有分页功能PageHelper

    SpringBoot集成Mybatis并具有分页功能PageHelper   环境:IDEA编译工具   第一步:生成测试的数据库表和数据   SET FOREIGN_KEY_CHECKS=0;   ...

随机推荐

  1. Spring Security 实战干货:图解用户是如何登录的

    1. 前言 欢迎阅读Spring Security 实战干货系列文章,在集成Spring Security安全框架的时候我们最先处理的可能就是根据我们项目的实际需要来定制注册登录了,尤其是Http登录 ...

  2. linux的/etc/passwd、/etc/shadow、/etc/group和/etc/gshadow

    1./etc/passwd  存储用户信息 [root@oldboy ~]# head /etc/passwd root:x:::root:/root:/bin/bash bin:x:::bin:/b ...

  3. python自带函数

    callable() #是否可以被执行,是否可以被调用 chr() #返回整数i对应的ASCII字符.与ord()作用相反.参数x:取值范围[0, 255]之间的正数. ord() #参数是一个asc ...

  4. DOM事件操作

    DOM事件:对事件做出反应 当事件发生时,可以执行 JavaScript,比如:点击时 onClick="" 例:当用户点击时,会改变 <h1> 元素的内容: < ...

  5. Python for循环语句

    Python for 循环语句:遍历任何序列的项目,可以是字符串.列表.元组.字典.集合对象. 流程图: 第一种: ''' for 迭代对象 in 序列: 代码块(一行语句或多行代码) ''' 第二种 ...

  6. Python获取当前时间_获取格式化时间_格式化日期

    Python获取当前时间_获取格式化时间: Python获取当前时间: 使用 time.time( ) 获取到距离1970年1月1日的秒数(浮点数),然后传递给 localtime 获取当前时间 #使 ...

  7. 提取txt文本有效内容

    原理: 1.使用足够多的垃圾邮件和非垃圾邮件的内容作为训练集 2.读取全部训练集 删除其中的干扰字符 [ ] ,* . 进行分词 删除长度为 1 的单个字符 3.统计全部训练集中每个有效词汇的出现次数 ...

  8. __new__方法理解

    class Foo(object): def __init__(self, *args, **kwargs): pass def __new__(cls, *args, **kwargs): retu ...

  9. Kafka和SpringBoot

    事先必备: kafka已安装完成 1.目录结构 2.父pom <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  10. PHP ftruncate() 函数

    定义和用法 ftruncate() 函数把打开文件截断到指定的长度. 如果成功则返回 TRUE,如果失败则返回 FALSE. 语法 ftruncate(file,size) 参数 描述 file 必需 ...