springBoot单元测试-基础单元测试
1)在pom文件中加入junit支持
<!-- spring-boot-starter-test 单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2)新建测试类 Application1Test
在class 头上增加注解
@RunWith(SpringRunner.class) :指定运行平台,点进去 SpringRunner.class 可以看到他是集成自 SpringJUnit4ClassRunner
@SpringBootTest : 标记此类为方法测试类,在加载和其他扫描是spring不会去对他进行扫描
@RunWith(SpringRunner.class)
@SpringBootTest
public class Application1Test { @Test
public void test1() { //业务逻辑代码
System.err.println("this is test1 !"); }
@Test
public void test2() { //业务逻辑代码
System.err.println("this is test2 !"); } // @Before 标记 在执行Test 前执行该方法
@Before
public void testBefore() { //业务逻辑代码
System.err.println("this is testBefore !"); } // @After 标记 在执行Test 后执行该方法
@After
public void testAfter() { //业务逻辑代码
System.err.println("this is testAfter !"); } }
认为 springBoot的实际运用场景并不是很多,但可以用在像计算一段复杂代码的执行时间,比如数据库连接耗时等需求上
springBoot单元测试-基础单元测试的更多相关文章
- python基础——单元测试
python基础——单元测试 如果你听说过“测试驱动开发”(TDD:Test-Driven Development),单元测试就不陌生. 单元测试是用来对一个模块.一个函数或者一个类来进行正确性检验的 ...
- JUnit单元测试基础要点
JUnit单元测试基础要点 1.JUnit是一种测试代码的框架,测试的目的是:保证代码没错,而不是保证代码正确. 2.测试类一般不要和目标类放在一起,但编译成的class文件是放在一起的. 3.单元测 ...
- springboot Service层单元测试
两个实现类实现同一个Service接口 public interface CustomUrlService { List<ShopMetrics> getShopMetrics(); } ...
- 【快学springboot】在springboot中写单元测试[Happyjava]
前言 很多公司都有写单元测试的硬性要求,在提交代码的时候,如果单测通不过或者说单元测试各种覆盖率不达标,会被拒绝合并代码.写单元测试,也是保证代码质量的一种方式. junit单元测试 相信绝大多数的J ...
- 【快学springboot】在springboot中写单元测试
前言 很多公司都有写单元测试的硬性要求,在提交代码的时候,如果单测通不过或者说单元测试各种覆盖率不达标,会被拒绝合并代码.写单元测试,也是保证代码质量的一种方式. junit单元测试 相信绝大多数的J ...
- 【SpringBoot】SpringBoot的基础,全面理解bean的生命周期
前言 前段时间直接上手使用springboot开发了一个数据平台的后台部分,但是自身对于springboot的原理和过程还不是很清晰,所以反过来学习下springboot的基础. 大家都知道sprin ...
- SpringBoot之基础入门-专题一
SpringBoot之基础入门-专题一 一.Spring介绍 1.1.SpringBoot简介 在初次学习Spring整合各个第三方框架构建项目的时候,往往会有一大堆的XML文件的配置,众多的dtd或 ...
- 从SpringBoot到SpringCloudAlibaba简明教程(一):初识SpringBoot及其基础项目构建
前言 Spring框架的大名想必大家早已如雷贯耳,我们来看一下springboot诞生的初衷,以及它在springframe的基础上解决了哪些痛点. 很久以前,J2EE还是java企业级应用的标准规范 ...
- Spring入门(二):SpringBoot之基础Web开发
接上回 现在,我们已经能自行完成SpringBoot的初级项目搭建了,接下来看如何实现一些Web开发中的基础功能. 先看项目完整的目录结构: 1. 返回Json数据 创建model文件夹,并新建Per ...
随机推荐
- django wsgi nginx 配置
""" WSGI config for HelloWorld project. It exposes the WSGI callable as a module-leve ...
- 流程控制--if条件
/* if ....else .... */ [root@localhost test1]# vim .py //ADD #!/usr/bin/python >: print 'hello py ...
- C#文件路径乱码
最近学C#,用C#写serialport遇到了一点小问题记录一下. 问题一: if (!string.IsNullOrEmpty(filePath.ToString())) { try { fs = ...
- NEERC 2016-2017 Probelm G. Game on Graph
title: NEERC 2016-2017 Probelm G. Game on Graph data: 2018-3-3 22:25:40 tags: 博弈论 with draw 拓扑排序 cat ...
- Request对象与Response对象
1.Request对象 Request对象是来获取请求消息的,是由服务器(Tomcat)创建的. Request对象继承体系结构: ServletRequest -- 接口 ...
- Multiply Strings——面试题
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- ps -ef和ps aux的区别
ps -ef 是用标准格式(standard syntax)显示进程 ,ps aux 是用BSD格式(BSD syntax)来显示进程 ps -ef 结果如下: 部分含义如下: PPID //父进程I ...
- ssm框架问题和Java
http://blog.csdn.net/zzjjiandan/article/details/20853233 BeanFactory的作用是什么? BeanFactory是配置.创建.管理bean ...
- AC日记——统计和 洛谷 P2068
统计和 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 int n,m,tree ...
- Ubuntu18.04 安装Chrome浏览器
一路copy paste就OK sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources. ...