1.添加测试依赖

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

2.添加启动类和测试类

package top.ytheng.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication //等于下面3个
//@SpringBootConfiguration
//@EnableAutoConfiguration
//@ComponentScan
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
} }
package top.ytheng.demo;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import junit.framework.TestCase; //底层用junit SpringJunit4ClassRunner
@RunWith(SpringRunner.class)
//启动整个Springboot工程
@SpringBootTest(classes= {DemoApplication.class})
//鼠标选中SpringBootTestDemo后执行Run As -> JUnit Test可以同时执行多个测试
public class SpringBootTestDemo {
@Test
public void testOne() {
System.out.println("test hello 1");
TestCase.assertEquals(1, 1);
} @Test
public void testTwo() {
System.out.println("test hello 2");
TestCase.assertEquals(1, 1);
} @Before
public void testBefore() {
System.out.println("test before");
} //@Test之后调用
//一般进行资源的回收利用
@After
public void testAfter() {
System.out.println("test after");
}
}

3.选中需要测试的方法,右键->Run AS->JUnit Test即可

SpringBoot------单元测试的更多相关文章

  1. Springboot单元测试Junit深度实践

    Springboot单元测试Junit深度实践 前言 单元测试的好处估计大家也都知道了,但是大家可以发现在国内IT公司中真正推行单测的很少很少,一些大厂大部分也只是在核心产品推广单测来保障质量,今天这 ...

  2. springmvc,springboot单元测试配置

    1. springmvc单元测试配置 <dependency> <groupId>junit</groupId> <artifactId>junit&l ...

  3. SpringBoot单元测试中的事务和Session

    1.Springboot中使用junit编写单元测试,并且测试结果不影响数据库. 2.

  4. SpringBoot单元测试

    一.Service层Junit单元测试 需要的jar包 <dependency> <groupId>org.springframework.boot</groupId&g ...

  5. springboot(十二):springboot单元测试、打包部署

    单元测试 1.在pom包中添加spring-boot-starter-test包引用 <dependency> <groupId>org.springframework.boo ...

  6. springboot系列三、springboot 单元测试、配置访问路径、多个配置文件和多环境配置,项目打包发布

    一.单元测试 生成的demo里面包含spring-boot-starter-test :测试模块,包括JUnit.Hamcrest.Mockito,没有的手动加上. <dependency> ...

  7. Springboot单元测试(MockBean||SpyBean)

    转载:https://blog.csdn.net/maiyikai/article/details/78483423 本来要写springboot集成netty实现的,但是想起来单元测试没总结,那就趁 ...

  8. 五、springboot单元测试

    1.为什么要写测试用例 1. 可以避免测试点的遗漏,为了更好的进行测试,可以提高测试效率 2. 可以自动测试,可以在项目打包前进行测试校验 3. 可以及时发现因为修改代码导致新的问题的出现,并及时解决 ...

  9. springBoot单元测试-基础单元测试

    1)在pom文件中加入junit支持 <!-- spring-boot-starter-test 单元测试 --> <dependency> <groupId>or ...

  10. 【使用篇二】SpringBoot单元测试(10)

    SpringCloud单元测试:https://www.cnblogs.com/myitnews/p/11796321.html 1. 创建项目Maven Project,修改pom.xml < ...

随机推荐

  1. 阿里开源项目 druid 相关资料汇总

    项目发起人访谈:http://www.iteye.com/magazines/90 github主页:https://github.com/alibaba/druid druid 项目,我想我能用很短 ...

  2. postgresql ltree类型

    最近一个月使用Postgresql的时候,经常遇到ltree的数据,感觉有些别扭,可是有绕不过去.今天决心整理一下,以后使用方便一些. 一.简介 ltree是Postgresql的一个扩展类型,由两位 ...

  3. textAngular字体依赖

    textAngular部分按钮显示不正常, 对比后发现是少了字体css <link href="https://cdn.bootcss.com/font-awesome/4.7.0/c ...

  4. 使用Java合并图片、修改DPI

    项目中有时候需要对图片进行DPI.合并.拼接等的处理: package com.snow.web.a_test; import java.awt.Graphics; import java.awt.i ...

  5. 【C语言】数组名传递给函数,数组的sizeof变为4的原因

    C语言中,数组名作为参数传递给函数时,退化为指针,sizeof对指针操作结果应该是4.例子如下: #include<iostream> using namespace std; void ...

  6. asp.net C# int 类型在32/64位环境下取值范围无变化

    最近在学习中突然想到,我在64位环境下,int取值范围是否有变化?为了检测这个结果,我做了以下这个测试:1.环境:win7旗舰版64位+vs2010 sp1(版本号:10.0.40219.1SP1Re ...

  7. SNF开发平台WinForm之十五-时间轴控件使用-SNF快速开发平台3.3-Spring.Net.Framework

    一.显示效果如下: 二.在控件库里选择UCTimeAxis 拖拽到窗体里. 三.加入以下代码,在load事件里进行调用就可以运行了. #region 给时间轴控件加载数据 private void U ...

  8. appium 获取android 粘贴板上的内容

    appium 新版本增加了获取粘贴板的内容.如果使用appium旧版本,获取粘贴板的内容不是那么容易的,甚至百度谷歌各种搜,都无法找到合适的解决方法.新版本获取android 粘贴板内容就显得很容易了 ...

  9. 《ZooKeeper分布式专题与Dubbo微服务入门》

    最近在慕课网新上的课程,有兴趣的朋友可以关注一波 http://coding.imooc.com/class/201.html

  10. 【Android】开源项目UniversalImageLoader及开源框架ImageLoader

    UniversalImageLoader 简单来说就是用于加载图片的一个开源项目,在其项目介绍中是这么写的 支持多线程图片加载 提供丰富的细节配置,比如线程池大小,HTPP请求项,内存和磁盘缓存,图片 ...