JUnit 5
JUnit 5
JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
:
JUnit Platform: 启动Junit 测试、IDE、构建工具或插件都需要包含和扩展Platform API ,它定义了TestEngine 在平台运行的新测试框架的API 。它还提供了一个控制台启动器,可以从命令行启动Platform ,为Gradle 和Maven 插件提供支持。JUnit Jupiter: 它用于编写测试代码的新的编程和扩展模型。它具有所有新的Junit 注释和TestEngine 实现来运行这些注释编写的测试。JUnit Vintage: 它主要的目的是支持在JUnit5 的测试代码中运行JUnit3 和4 方式写的测试,它能够向前兼容之前的测试代码。

快速开始
使用
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
或者在
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0-M4")
testRuntime("org.junit.platform:junit-platform-runner:1.0.0-M4")
Tips: 无论是单元测试,还是集成测试,我们都必须小心地控制代码的边界,避免耦合带来的意外失败,并提高用例地运行效率。