Add JUnit 5 @RepeatedTest demo project

Initial commit of a Maven project demonstrating JUnit 5's @RepeatedTest annotation. Includes example tests for basic repetition, custom display names, metadata injection, lifecycle management, and failure thresholds. Project files include .gitignore, README, pom.xml, and test classes under src/test/java/com/ankurm/tutorials/junit/repeated.
This commit is contained in:
Ankur
2025-12-31 17:38:29 +05:30
commit 5ed079dff3
8 changed files with 188 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
# JUnit 5 @RepeatedTest Demonstration
This project demonstrates the usage of JUnit 5's `@RepeatedTest` annotation to improve test reliability and handle flaky tests.
## Concepts Covered
The code examples in `src/test/java/com/ankurTutorials/junit/repeated` cover the following concepts:
1. **Basic Repetition**: Repeating a test a specific number of times.
- File: `ReliabilityTest.java`
2. **Custom Display Names**: Configuring formatted names for each repetition for better reporting in CI/CD.
- File: `CustomNameTest.java`
3. **Metadata Injection**: Using `RepetitionInfo` to access the current repetition index and total count within the test.
- File: `MetadataTest.java`
4. **Lifecycle Management**: Understanding how `@BeforeEach` and `@AfterEach` interact with repeated tests (they run for *each* repetition).
- File: `LifecycleTest.java`
5. **Failure Thresholds**: Using the `failureThreshold` attribute (JUnit 5.10+) to stop execution early if a certain number of failures occur.
- File: `FlakyServiceTest.java`
## Prerequisites
- Java 17 or higher
- Maven 3.6+
## How to Run
To run all tests, execute the following command in the project root:
```bash
mvn test
```
To run a specific test class:
```bash
mvn -Dtest=BasicUsageTest test
```