Browse Source

bz-63680 Fix the LegacyXmlResultFormatter to recursively look for a parent testclass name, until it finds one

master
Jaikiran Pai 5 years ago
parent
commit
5981e1bff1
2 changed files with 19 additions and 9 deletions
  1. +5
    -0
      WHATSNEW
  2. +14
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java

+ 5
- 0
WHATSNEW View File

@@ -21,6 +21,11 @@ Fixed bugs:
has now been fixed.
Bugzilla Report 63446

* The "legacy-xml" junitlauncher task's listener would not include
@ParameterizedTest testcases in its XML report file. This has now
been fixed.
Bugzilla Report 63680

Other changes:
--------------



+ 14
- 9
src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java View File

@@ -236,19 +236,14 @@ class LegacyXmlResultFormatter extends AbstractJUnitResultFormatter implements T
continue;
}
// find the parent class of this test method
final Optional<TestIdentifier> parent = testPlan.getParent(testId);
if (!parent.isPresent() || !parent.get().getSource().isPresent()) {
// we need to know the parent test class, else we aren't interested
final Optional<ClassSource> parentClassSource = findFirstParentClassSource(testId);
if (!parentClassSource.isPresent()) {
continue;
}
final TestSource parentSource = parent.get().getSource().get();
if (!(parentSource instanceof ClassSource)) {
continue;
}
final String classname = ((ClassSource) parentSource).getClassName();
final String classname = (parentClassSource.get()).getClassName();
writer.writeStartElement(ELEM_TESTCASE);
writer.writeAttribute(ATTR_CLASSNAME, classname);
writer.writeAttribute(ATTR_NAME, testId.getDisplayName());
writer.writeAttribute(ATTR_NAME, testId.getLegacyReportingName());
final Stats stats = entry.getValue();
writer.writeAttribute(ATTR_TIME, String.valueOf((stats.endedAt - stats.startedAt) / ONE_SECOND));
// skipped element if the test was skipped
@@ -375,6 +370,16 @@ class LegacyXmlResultFormatter extends AbstractJUnitResultFormatter implements T
}
return Optional.empty();
}

private Optional<ClassSource> findFirstParentClassSource(final TestIdentifier testId) {
final Optional<TestIdentifier> parent = testPlan.getParent(testId);
if (!parent.isPresent() || !parent.get().getSource().isPresent()) {
return Optional.empty();
}
final TestSource parentSource = parent.get().getSource().get();
return parentSource instanceof ClassSource ? Optional.of((ClassSource) parentSource)
: findFirstParentClassSource(parent.get());
}
}

}

Loading…
Cancel
Save