1. 引入spring-boot-starter-test包

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5
 6     <groupId>com.example</groupId>
 7     <artifactId>java8demo</artifactId>
 8     <version>0.0.1-SNAPSHOT</version>
 9     <packaging>jar</packaging>
10
11     <name>java8demo</name>
12     <description>Java8 Demo project for Spring Boot</description>
13
14     <parent>
15         <groupId>org.springframework.boot</groupId>
16         <artifactId>spring-boot-starter-parent</artifactId>
17         <version>2.0.5.RELEASE</version>
18         <relativePath/> <!-- lookup parent from repository -->
19     </parent>
20
21     <properties>
22         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24         <java.version>1.8</java.version>
25     </properties>
26
27     <dependencies>
28         <dependency>
29             <groupId>org.springframework.boot</groupId>
30             <artifactId>spring-boot-starter-web</artifactId>
31         </dependency>
32
33         <dependency>
34             <groupId>org.projectlombok</groupId>
35             <artifactId>lombok</artifactId>
36             <optional>true</optional>
37         </dependency>
38         <dependency>
39             <groupId>org.springframework.boot</groupId>
40             <artifactId>spring-boot-starter-test</artifactId>
41             <!--<scope>test</scope>-->
42         </dependency>
43     </dependencies>
44
45     <build>
46         <plugins>
47             <plugin>
48                 <groupId>org.springframework.boot</groupId>
49                 <artifactId>spring-boot-maven-plugin</artifactId>
50             </plugin>
51         </plugins>
52     </build>
53
54
55 </project>

2. 记得在自己测试时,导包有问题的话,是要记得去掉spring-boot-starter-test中的scope范围,只需要三个注解就行

 1 package com.example.java8demo;
 2
 3 import org.junit.Test;
 4 import org.junit.runner.RunWith;
 5 import org.springframework.boot.test.context.SpringBootTest;
 6 import org.springframework.test.context.junit4.SpringRunner;
 7
 8 import java.time.*;
 9 import java.time.format.DateTimeFormatter;
10 import java.time.temporal.TemporalAdjusters;
11 import java.util.Set;
12
13 /**
14  * java 8 对于日期和时间的使用
15  * API文档:https://blog.fondme.cn/apidoc/jdk-1.8-google/下的java.time包下
16  */
17 @RunWith(SpringRunner.class)
18 @SpringBootTest // 指定启动类
19 public class LocalDateTimeTest {
20       /**
21      * 5. DateTimeFormatter : 解析和格式化日期或时间
22      */
23     @Test
24     public void test5(){
25
26         DateTimeFormatter dateTimeFormater = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒");
27         LocalDateTime localDateTime = LocalDateTime.now();
28         System.out.println("【----未格式化之前----】" + localDateTime);
29         System.out.println("【----格式化之后----】"+dateTimeFormater.format(localDateTime));
30     }
31 }

官方文档,可参考:https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#boot-features-testing

转载于:https://www.cnblogs.com/move22/p/9701067.html

Springboot 2.0.0单元测试相关推荐

  1. SpringBoot集成Mybatis(0配置注解版)

    Mybatis初期使用比较麻烦,需要各种配置文件.实体类.dao层映射关联.还有一大推其它配置.当然Mybatis也发现了这种弊端,初期开发了generator可以根据表结构自动生成实体类.配置文件和 ...

  2. Springboot(2.0.0.RELEASE)+spark(2.1.0)框架整合到jar包成功发布(原创)!!!

    一.前言 首先说明一下,这个框架的整合可能对大神来说十分容易,但是对我来说十分不易,踩了不少坑.虽然整合的时间不长,但是值得来纪念下!!!我个人开发工具比较喜欢IDEA,创建的springboot的j ...

  3. springboot mybatis mysql8.0 异常 invalid bound statement (not found)(汇总篇)

    大家好,我是烤鸭: 现在是采坑实录. invalid bound statement (not found)  这个坑用过mybatis的人肯定都踩过. 1. 环境 <parent>< ...

  4. Jeecg-Boot 2.0.0 版本发布,基于Springboot+Vue 前后端分离快速开发平台

    Jeecg-Boot 2.0.0 版本发布,前后端分离快速开发平台 Jeecg-Boot项目简介 源码下载 升级日志 Issues解决 v1.1升级到v2.0不兼容地方 系统截图 Jeecg-Boot ...

  5. SpringBoot实战教程(1)| 整合Swagger3.0.0

    本文教你如何在SpringBoot中整合Swagger,快速实现在线接口文档. Swagger版本:3.0.0 SpringBoot版本:2.5.6 目录 一.初始化SpringBoot项目 二.引入 ...

  6. idea运行springboot出现 Disconnected from the target VM, address: ‘127.0.0.1:xxxx‘, transport: ‘socket‘

    idea运行springboot出现 Disconnected from the target VM, address: '127.0.0.1:xxxx', transport: 'socket' 1 ...

  7. Cat3.0.0监控本地部署+springboot接入cat例子

    Cat监控本地部署 说明 目标 前提 cat.war和sql脚本 源码下载 编译 sql脚本----mysql这里就配置完了 部署cat springboot程序接入cat win10本地配置 my- ...

  8. SpringBoot使用mybatis-autogenerator时,显示Failure to find org.eclipse.m2e:lifecycle-mapping:pom:1.0.0错误

    SpringBoot使用mybatis-autogenerator子自动生成代码时候,报如下错误: Failure to find org.eclipse.m2e:lifecycle-mapping: ...

  9. 解决springboot整合dubbo中No provider available from registry 127.0.0.1:2181 for service x.x.x on consumer

    解决springboot整合dubbo中No provider available from registry 127.0.0.1:2181 for service x.x.x on consumer ...

最新文章

  1. Hinton向量学院推出神经ODE:超越ResNet 4大性能优势
  2. 对实体 characterEncoding 的引用必须以 ';' 分隔符结尾
  3. 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入
  4. 五十一、微信小程序云开发中的云函数
  5. JAVA 面向对象-2-继承(Inheritance)
  6. api 二次 开发 禅道_浅谈-软件开发流程
  7. Mysql学习笔记(六)增删改查
  8. 自定义shell脚本
  9. 系统集成资质培训 - 论文:论项目的人力资源管理
  10. 依赖倒转原则_Java设计模式的七大原则
  11. java时间管理番茄时钟小程序源码
  12. [游戏安全] Unity3D游戏无意中的发现
  13. android 自定义view实现仿QQ运动步数进度效果
  14. iOS 【使用自定义字体-苹方字体】
  15. 20180710使用gh
  16. 设计模式六大原则的理解与归纳
  17. 智能问答(Question Answering)的主要研究方向
  18. python正则表达式入门
  19. debian系统安装dig和nslookup工具
  20. jquery checkbox选中事件监听

热门文章

  1. Zabbix3.2安装
  2. 74-A/D指标,Accumulation/Distribution,积累/派发线,离散指标.(2015.7.1)
  3. 车牌识别之车牌定位(方案总结)
  4. 【托管服务qin】WEB网站压力测试教程详解
  5. spring boot 带远程调试启动方式
  6. Windows Server 2003 DNS服务安装篇
  7. remoteing2
  8. 算法之美 : 位运算
  9. Java 9 新功能之 HTTP2 和 REPL
  10. Linux环境下安装部署AWStats日志分析系统实例