Failure Threshold Support for @RepeatedTest in Junit

This commit is contained in:
michaelin007 2023-12-11 06:18:58 +00:00
parent b0be6dbf36
commit 62195e14d4
2 changed files with 6 additions and 12 deletions

View File

@ -1,21 +1,16 @@
package com.baeldung.junit5.failurethreshold;
import org.junit.jupiter.api.RepeatedTest;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;
import static org.junit.jupiter.api.Assertions.assertTrue;
class FailureThresholdUnitTest {
Random random = new Random();
@RepeatedTest(value = 5, failureThreshold = 1)
void givenTextFile_whenItIsReadAndContainsSpecifiedWordRepeatedly_thenMatchingLinesFound() throws IOException {
String filePath = "test_file.txt";
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line = reader.readLine();
assertTrue(line.contains("The"));
}
@RepeatedTest(value = 10, failureThreshold = 2)
void givenRandomNumberGenerator_whenGeneratingRandomNumber_thenNumberShouldBeWithinRange() {
int number = random.nextInt(10);
assertTrue(number <= 9);
}
}

View File

@ -1 +0,0 @@
The Efficacy of meta-cognitive therapy on the symptoms of obsessive-compulsive disorder in patients with multiple sclerosis