Files
JUnit_Tutorials/RepeatedTest/README.md
T
Ankur 5ed079dff3 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.
2025-12-31 17:38:29 +05:30

37 lines
1.3 KiB
Markdown

# 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
```