SpringBoot 单元测试,系列文章:
1、JUnit5 的使用教程
1.1 简介
JUnit是一个Java语言的单元测试框架。它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个。 JUnit有它自己的JUnit扩展生态圈。多数Java的开发环境都已经集成了JUnit作为单元测试的工具。
JUnit5旨在调整java8样式的编码,并且比JUnit4更强大和灵活。
什么是Junit5
JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
这看上去比Junit4 复杂,实际上在导入包时也会复杂一些。
JUnit Platform:是在JVM上启动测试框架的基础。
JUnit Jupiter:是JUnit5扩展的新的编程模型和扩展模型,用来编写测试用例。Jupiter子项目为在平台上运行Jupiter的测试提供了一个TestEngine (测试引擎)。
JUnit Vintage:提供了一个在平台上运行JUnit 3和JUnit 4的TestEngine 。
1.2 安装
这里使用Maven进行安装,pom.xml配置文件如下:
<dependencies>
<!-- JUnit5单元测试框架 -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</sc

本文详细介绍了JUnit5的使用教程,包括JUnit5的结构、安装配置、注解使用及断言方法,通过一个IDEA中的实例展示了如何进行单元测试。
1191

被折叠的 条评论
为什么被折叠?



