in surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java [102:192]
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (valid) {
try {
switch (qName) {
case "testsuite":
defaultSuite = new ReportTestSuite();
currentSuite = defaultSuite;
String timeStr = attributes.getValue("time");
if (timeStr != null) {
defaultSuite.setTimeElapsed(Float.parseFloat(timeStr));
} else {
consoleLogger.warning("No time attribute found on testsuite element");
}
final String name = attributes.getValue("name");
final String group = attributes.getValue("group");
defaultSuite.setFullClassName(
isBlank(group)
? /*name is full class name*/ name
: /*group is package name*/ group + "." + name);
suites.add(defaultSuite);
classesToSuitesIndex.put(defaultSuite.getFullClassName(), suites.size() - 1);
break;
case "testcase":
// Although this element does not contain any text, this line must be retained because the
// nested elements do have text content.
currentElement = new StringBuilder();
testCase = new ReportTestCase().setName(attributes.getValue("name"));
String fullClassName = attributes.getValue("classname");
// if the testcase declares its own classname, it may need to belong to its own suite
if (fullClassName != null) {
Integer currentSuiteIndex = classesToSuitesIndex.get(fullClassName);
if (currentSuiteIndex == null) {
currentSuite = new ReportTestSuite().setFullClassName(fullClassName);
suites.add(currentSuite);
classesToSuitesIndex.put(fullClassName, suites.size() - 1);
} else {
currentSuite = suites.get(currentSuiteIndex);
}
}
timeStr = attributes.getValue("time");
testCase.setFullClassName(currentSuite.getFullClassName())
.setClassName(currentSuite.getName())
.setFullName(currentSuite.getFullClassName() + "." + testCase.getName())
.setTime(timeStr != null ? Float.parseFloat(timeStr) : 0.0f);
if (currentSuite != defaultSuite) {
currentSuite.setTimeElapsed(testCase.getTime() + currentSuite.getTimeElapsed());
}
break;
case "failure":
currentElement = new StringBuilder();
testCase.setFailure(attributes.getValue("message"), attributes.getValue("type"));
currentSuite.incrementNumberOfFailures();
break;
case "error":
currentElement = new StringBuilder();
testCase.setError(attributes.getValue("message"), attributes.getValue("type"));
currentSuite.incrementNumberOfErrors();
break;
case "skipped":
String message = attributes.getValue("message");
testCase.setSkipped(message != null ? message : "skipped");
currentSuite.incrementNumberOfSkipped();
break;
case "flakyFailure":
case "flakyError":
currentSuite.incrementNumberOfFlakes();
break;
case "failsafe-summary":
valid = false;
break;
case "time":
currentElement = new StringBuilder();
break;
default:
break;
}
} catch (NumberFormatException e) {
throw new SAXException("Failed to parse time value", e);
}
}
}