Skip to content

Instantly share code, notes, and snippets.

@b1a9id
Last active December 30, 2017 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b1a9id/78f2616f82fea49c95a6e71995e4681f to your computer and use it in GitHub Desktop.
Save b1a9id/78f2616f82fea49c95a6e71995e4681f to your computer and use it in GitHub Desktop.
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class RepeatedTestDemo {
@BeforeEach
void beforeEach(TestInfo testInfo, RepetitionInfo repetitionInfo) {
// 現在の回数
int currentRepetition = repetitionInfo.getCurrentRepetition();
// 実行すべき回数
int totalRepetitions = repetitionInfo.getTotalRepetitions();
// テストクラス名
String testClass = testInfo.getTestClass().get().getName();
// テストメソッド名
String methodName = testInfo.getTestMethod().get().getName();
System.out.println(String.format("About to execute repetition %d of %d for %s#%s", //
currentRepetition, totalRepetitions, testClass, methodName));
}
// 3回実行
@RepeatedTest(3)
void noArgs() {
assertTrue("test".length() == 4);
}
@RepeatedTest(3)
void totalRepetitionsInfo(RepetitionInfo repetitionInfo) {
assertEquals(3, repetitionInfo.getTotalRepetitions());
}
@RepeatedTest(value = 3, name = "{displayName} {currentRepetition}/{totalRepetitions}")
@DisplayName("Custom Repeated Test!!")
void customDisplayName(TestInfo testInfo, RepetitionInfo repetitionInfo) {
int currentRepetition = repetitionInfo.getCurrentRepetition();
int totalRepetitions = repetitionInfo.getTotalRepetitions();
assertEquals(String.format("Custom Repeated Test!! %d/%d", currentRepetition, totalRepetitions), testInfo.getDisplayName());
}
@RepeatedTest(value = 1, name = RepeatedTest.LONG_DISPLAY_NAME)
@DisplayName("Details...")
void customDisplayNameLongPattern(TestInfo testInfo) {
assertEquals("Details... :: repetition 1 of 1", testInfo.getDisplayName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment