Skip to content

Instantly share code, notes, and snippets.

@Seijan
Created November 1, 2019 18:23
Show Gist options
  • Save Seijan/a0c1900e2ba6dcc6642ea81f1ac6f065 to your computer and use it in GitHub Desktop.
Save Seijan/a0c1900e2ba6dcc6642ea81f1ac6f065 to your computer and use it in GitHub Desktop.
Rerunning a parameterized test
@Test
public void rerunWithParameterizedTests()
throws TestSetFailedException
{
Launcher launcher = LauncherFactory.create();
ProviderParameters parameters = providerParametersMock();
// Mock the rerun variable
when( parameters.getTestRequest().getRerunFailingTestsCount() ).thenReturn( 1 );
JUnitPlatformProvider provider = new JUnitPlatformProvider( parameters, launcher );
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
launcher.registerTestExecutionListeners( executionListener );
invokeProvider( provider, TestClass6.class );
// two tests have to be started, one success, one fail
assertThat( executionListener.summaries ).hasSize( 2 );
TestExecutionSummary summary = executionListener.summaries.get( 0 );
assertEquals( 2, summary.getTestsFoundCount() );
assertEquals( 2, summary.getTestsStartedCount() );
assertEquals( 1, summary.getTestsSucceededCount() );
assertEquals( 1, summary.getTestsFailedCount() );
Set<String> failDisplays = new HashSet<>();
for ( TestExecutionSummary.Failure failure : summary.getFailures() )
{
failDisplays.add( failure.getTestIdentifier().getDisplayName() );
}
assertEquals( 1, failDisplays.size() );
assertTrue( failDisplays.contains( "[2] Test always fails, false" ) );
// now only one test should remain to be rerun
summary = executionListener.summaries.get( 1 );
assertEquals( 1, summary.getTestsFoundCount() );
assertEquals( 1, summary.getTestsStartedCount() );
assertEquals( 0, summary.getTestsSucceededCount() );
assertEquals( 1, summary.getTestsFailedCount() );
}
static class TestClass6
{
static List<Object[]> parameters() {
//always pass
Object[] testOne = new Object[]{
"Test always passes",
true,
};
//should always fail
Object[] testTwo = new Object[]{
"Test always fails",
false,
};
return asList(testOne, testTwo);
}
@ParameterizedTest
@MethodSource("parameters")
void testParameterizedTestCases(String testName, boolean value) {
assertTrue(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment