JUnit 5 示例项目教程
1. 项目的目录结构及介绍
JUnit 5 示例项目的目录结构如下:
junit5-samples/
├── junit5-jupiter-starter-ant/
├── junit5-migration-gradle/
├── junit5-migration-maven/
├── junit5-modular-world/
├── junit5-multiple-engines/
├── junit5-exception-testing-example/
├── junit5-assumptions/
├── junit5-nested-test-example/
├── junit5-dynamic-test-example/
├── junit5-maven-example/
├── junit5-spring-boot-example/
├── junit5-tag-filter-example/
├── junit5-test-suite-example/
├── junit5-timeout-example/
└── README.md
目录结构介绍
junit5-jupiter-starter-ant/
: 展示了如何在 Ant 中使用 JUnit Jupiter。junit5-migration-gradle/
: 展示了如何在 Gradle 项目中设置 JUnit Platform、JUnit Jupiter 和 JUnit Vintage。junit5-migration-maven/
: 展示了如何在 Maven 项目中设置 JUnit Platform、JUnit Jupiter 和 JUnit Vintage。junit5-modular-world/
: 展示了如何在模块化的世界中测试代码,并实现自定义的 TestEngine。junit5-multiple-engines/
: 展示了如何在 Gradle 项目中使用 JUnit Platform 和多个 TestEngine。junit5-exception-testing-example/
: 展示了如何进行异常测试。junit5-assumptions/
: 展示了如何使用假设(Assumptions)。junit5-nested-test-example/
: 展示了如何进行嵌套测试。junit5-dynamic-test-example/
: 展示了如何在运行时生成动态测试。junit5-maven-example/
: 展示了如何在 Maven 项目中使用 JUnit 5。junit5-spring-boot-example/
: 展示了如何在 Spring Boot 项目中使用 JUnit 5。junit5-tag-filter-example/
: 展示了如何进行标签过滤。junit5-test-suite-example/
: 展示了如何创建测试套件。junit5-timeout-example/
: 展示了如何进行超时测试。README.md
: 项目的介绍文件。
2. 项目的启动文件介绍
每个子项目的启动文件可能会有所不同,但通常会包含一个主要的测试类或配置文件。以下是一些示例:
junit5-jupiter-starter-ant/
src/test/java/com/example/junit5/ant/AntTest.java
: 主要的测试类。
junit5-migration-gradle/
src/test/java/com/example/junit5/migration/gradle/GradleTest.java
: 主要的测试类。
junit5-migration-maven/
src/test/java/com/example/junit5/migration/maven/MavenTest.java
: 主要的测试类。
junit5-modular-world/
src/test/java/com/example/junit5/modular/world/ModularWorldTest.java
: 主要的测试类。
junit5-multiple-engines/
src/test/java/com/example/junit5/multiple/engines/MultipleEnginesTest.java
: 主要的测试类。
3. 项目的配置文件介绍
每个子项目的配置文件也会有所不同,但通常会包含构建配置文件和测试配置文件。以下是一些示例:
junit5-jupiter-starter-ant/
build.xml
: Ant 构建文件。
junit5-migration-gradle/
build.gradle
: Gradle 构建文件。
junit5-migration-maven/
pom.xml
: Maven 构建文件。
junit5-modular-world/
module-info.java
: Java 模块描述文件。build.gradle
: Gradle 构建文件。
junit5-multiple-engines/
build.gradle
: Gradle 构建文件。