org.junit.jupiter.api.RepetitionInfo Java Examples

The following examples show how to use org.junit.jupiter.api.RepetitionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCaseFinderJunitJupiterTest.java    From recheck with GNU Affero General Public License v3.0 6 votes vote down vote up
@RepeatedTest( value = 2 )
void junit_jupiter_repeated_test_should_be_found( final RepetitionInfo repetitionInfo ) {
	final String expectedClassName = getClass().getName();
	final String expectedMethodName = "junit_jupiter_repeated_test_should_be_found";
	final TestCaseAnnotationType expectedType = TestCaseAnnotationType.REPEATABLE;
	final int expectedInvocationCount = repetitionInfo.getCurrentRepetition();

	final Optional<String> actualClassName = TestCaseFinder.getInstance().findTestCaseClassNameInStack();
	assertThat( actualClassName ).hasValue( expectedClassName );

	final Optional<String> actualMethodName = TestCaseFinder.getInstance().findTestCaseMethodNameInStack();
	assertThat( actualMethodName ).hasValueSatisfying( methodName -> methodName.startsWith( expectedMethodName ) );

	final TestCaseInformation info = TestCaseFinder.getInstance().findTestCaseMethodInStack();
	assertThat( info.getStackTraceElement().getClassName() ).isEqualTo( expectedClassName );
	assertThat( info.getStackTraceElement().getMethodName() ).isEqualTo( expectedMethodName );
	assertThat( info.getTestCaseAnnotationType() ).isEqualTo( expectedType );
	assertThat( info.getInvocationCount() ).isEqualTo( expectedInvocationCount );
}
 
Example #2
Source File: ItemTests.java    From jpms-module-names with MIT License 5 votes vote down vote up
@RepeatedTest(20)
void valueCountUnderflowThrows(RepetitionInfo info) {
  var i = info.getCurrentRepetition();
  var line = "-" + ",-".repeat(i - 1);
  if (i < 9) {
    var e = assertThrows(IllegalArgumentException.class, () -> new Item(line));
    assertEquals("Expected at least 9 values, only got " + i + " in: " + line, e.getMessage());
  } else {
    assertDoesNotThrow(() -> new Item(line));
  }
}
 
Example #3
Source File: RepeatedTestExample.java    From journaldev with MIT License 5 votes vote down vote up
@RepeatedTest(3)
void test_with_RepetitionInfo_Injection(RepetitionInfo repetitionInfo) {
	System.out.println("@RepeatedTest with RepetitionInfo Injection");
	assertEquals(3, repetitionInfo.getTotalRepetitions());

	// below code shouldn't be part of test method
	// move it to @BeforeEach/@AfterEach
	// System.out.println("Current Test Count = "+repetitionInfo.getCurrentRepetition());
}
 
Example #4
Source File: RepeatedInvocationTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@RepeatedTest(5)
void repeated(RepetitionInfo repetitions) {
	REPETITION_COUNT++;
	// RepetitionInfo::getCurrentRepetition starts with 1
	assertThat(repetitions.getCurrentRepetition()).isEqualTo(REPETITION_COUNT);
	assertThat(repetitions.getTotalRepetitions()).isEqualTo(5);
}
 
Example #5
Source File: RepetitionInfoTest.java    From mastering-junit5 with Apache License 2.0 4 votes vote down vote up
@RepeatedTest(2)
void test(RepetitionInfo repetitionInfo) {
    System.out.println("** Test " + repetitionInfo.getCurrentRepetition()
            + "/" + repetitionInfo.getTotalRepetitions());
}
 
Example #6
Source File: RepetitionInfoTest.java    From Mastering-Software-Testing-with-JUnit-5 with MIT License 4 votes vote down vote up
@RepeatedTest(2)
void test1(RepetitionInfo repetitionInfo) {
    System.out.println("** Test " + repetitionInfo.getCurrentRepetition()
            + "/" + repetitionInfo.getTotalRepetitions());
}
 
Example #7
Source File: RepeatedTests.java    From sbt-jupiter-interface with Apache License 2.0 4 votes vote down vote up
@RepeatedTest(5)
void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) {
    assertEquals(5, repetitionInfo.getTotalRepetitions());
}
 
Example #8
Source File: RepeatedTests.java    From sbt-jupiter-interface with Apache License 2.0 4 votes vote down vote up
@RepeatedTest(5)
void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) {
    assertEquals(5, repetitionInfo.getTotalRepetitions());
}
 
Example #9
Source File: RepeatedTests.java    From junit5-demo with Apache License 2.0 4 votes vote down vote up
@RepeatedTest(5)
void repeatedTest(RepetitionInfo repetitionInfo) {
	assertEquals(5, repetitionInfo.getTotalRepetitions());
}
 
Example #10
Source File: RepeatedTestExample.java    From journaldev with MIT License 4 votes vote down vote up
@BeforeEach
void setUp(RepetitionInfo repetitionInfo, TestInfo testInfo) {
	System.out.println("Method = " + testInfo.getTestMethod().get().getName() + ", Execution Count = "
			+ repetitionInfo.getCurrentRepetition());
}
 
Example #11
Source File: OrderTests.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@RepeatedTest(3)
@ExtendWith(RandomIntegerResolver.class)
void repetitionInfoFirst(RepetitionInfo info, TestReporter reporter, int randomized) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
Example #12
Source File: OrderTests.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@RepeatedTest(3)
@ExtendWith(RandomIntegerResolver.class)
void repetitionInfoLast(TestReporter reporter, int randomized, RepetitionInfo info) {
	reporter.publishEntry("first parameter", "" + randomized);
}
 
Example #13
Source File: RepeatedInvocationTest.java    From demo-junit-5 with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@DisplayName("Calling repeated...")
@RepeatedTest(
		value = 5,
		name = "... {currentRepetition}th "
				+ "of {totalRepetitions} times")
void repeatedWithDisplayName(RepetitionInfo repetitions) { }
 
Example #14
Source File: RepeatedTestAnnotationUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@RepeatedTest(3)
void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) {
    System.out.println("Repetition #" + repetitionInfo.getCurrentRepetition());
    assertEquals(3, repetitionInfo.getTotalRepetitions());
}
 
Example #15
Source File: IncrementTest.java    From tutorials with MIT License 4 votes vote down vote up
@RepeatedTest(value = 3, name = RepeatedTest.SHORT_DISPLAY_NAME)
public void test(RepetitionInfo info) {
    assertTrue(1 == 1);
    logger.info("Repetition #" + info.getCurrentRepetition());
}
 
Example #16
Source File: JUnit5StackTraceNamerTest.java    From ApprovalTests.Java with Apache License 2.0 4 votes vote down vote up
@RepeatedTest(2)
public void repeatedTest(RepetitionInfo repetitionInfo)
{
  StackTraceNamerUtils.assertNamerForFramework(getClass().getSimpleName(), "repeatedTest");
}