Skip to content

Commit

Permalink
Fix for test template retries. Also added test for parametrised tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertgrzeskowiak committed Oct 3, 2024
1 parent 01faf7f commit 8aaf0a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,31 +298,41 @@ public void testJupiterEngineWithFailureInTestTemplateProvider() {

@Test
public void testJupiterEngineWithTestTemplateNotClassifiedAsFlake() {
// Similar example, but using parameterized test (which is a test template under the hood)
//String testToRun = "ParamsContextTest";
String testToRun = "FieldSettingTest";
unpack("junit5-testtemplate-bug", "-" + jupiter)
.setTestToRun(testToRun)
.sysProp("junit5.version", jupiter)
//.debugSurefireFork()
.maven()
.withFailure()
.executeTest()
.verifyTextInLog("AssertionFailedError")
.assertTestSuiteResults(2, 0, 1, 0, 0);
.setTestToRun("FieldSettingTest")
.sysProp("junit5.version", jupiter)
.maven()
.withFailure()
.executeTest()
.verifyTextInLog("AssertionFailedError")
.assertTestSuiteResults(2, 0, 1, 0, 0);

unpack("junit5-testtemplate-bug", "-" + jupiter)
.debugLogging()
.setTestToRun("FieldSettingTest")
.sysProp("junit5.version", jupiter)
// The tests are failing deterministically, so rerunning them should not change the result
.sysProp("surefire.rerunFailingTestsCount", "1")
.maven()
.withFailure()
.executeTest()
.verifyTextInLog("AssertionFailedError")
.assertTestSuiteResults(2, 0, 1, 0, 0);
}

@Test
public void testJupiterEngineWithParameterizedTestsNotClassifiedAsFlake() {
unpack("junit5-testtemplate-bug", "-" + jupiter)
.debugLogging()
.setTestToRun(testToRun)
.sysProp("junit5.version", jupiter)
// The tests are failing deterministically, so rerunning them should not change the result
.sysProp("surefire.rerunFailingTestsCount", "1")
//.debugSurefireFork()
.maven()
.withFailure()
.executeTest()
.verifyTextInLog("AssertionFailedError")
.assertTestSuiteResults(2, 0, 1, 0, 0);
.debugLogging()
.setTestToRun("ParamsContextTest")
.sysProp("junit5.version", jupiter)
// The tests are failing deterministically, so rerunning them should not change the result
.sysProp("surefire.rerunFailingTestsCount", "1")
.maven()
.withFailure()
.executeTest()
.verifyTextInLog("AssertionFailedError")
.assertTestSuiteResults(2, 0, 1, 0, 0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,14 @@ private String[] toClassMethodName(TestIdentifier testIdentifier) {
boolean needsSpaceSeparator = isNotBlank(parentDisplay) && !display.startsWith("[");
String methodDisplay = parentDisplay + (needsSpaceSeparator ? " " : "") + display;

boolean isParameterized = isNotBlank(methodSource.getMethodParameterTypes());
boolean hasParameterizedParent = collectAllTestIdentifiersInHierarchy(testIdentifier)
.filter(identifier -> !identifier.getSource().isPresent())
.map(TestIdentifier::getLegacyReportingName)
.anyMatch(legacyReportingName -> legacyReportingName.matches("^\\[.+]$"));
boolean isTestTemplate = testIdentifier.getLegacyReportingName().matches("^.*\\[\\d+]$");

boolean parameterized = isNotBlank(methodSource.getMethodParameterTypes()) || hasParameterizedParent;
boolean parameterized = isParameterized || hasParameterizedParent || isTestTemplate;
String methodName = methodSource.getMethodName();
String description = testIdentifier.getLegacyReportingName();
boolean equalDescriptions = methodDisplay.equals(description);
Expand Down

0 comments on commit 8aaf0a6

Please sign in to comment.