Package rife.bld.extension.junitreporter
Class JUnitXmlParser
java.lang.Object
rife.bld.extension.junitreporter.JUnitXmlParser
Utility class to parse JUnit XML reports.
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic TestFailurecreateTestFailure(Element testCaseElement, Element failureElement, String defaultType) Creates aTestFailureinstance by extracting relevant failure information from a JUnit XML test case element and its associated failure element.static StringextractDisplayName(Element testCaseElement) Extracts the display-name from the system-out element within a test case.static Map<String,TestClassFailures> extractTestFailuresGrouped(String xmlFilePath) Extracts test failure information from a JUnit XML report and groups by class name.static StringgetAttributeOrDefault(Element element, String attributeName, String defaultValue) Retrieves the value of a specified attribute from the provided XML element.static StringgetTextContentTrimmed(Element element) Retrieves the trimmed text content of the specified XML element.static Map<String,TestClassFailures> parseTestCases(NodeList testCases) Parses a list of test case nodes from a JUnit XML report and groups the failures by their respective test class names.static doubleParses a time value represented as aStringand returns its numeric equivalent.static voidvalidateFile(Path path) Validates file existence and readability.
-
Field Details
-
MESSAGE_ATTR
- See Also:
-
NAME_ATTR
- See Also:
-
TESTCASE_TAG
- See Also:
-
-
Method Details
-
createTestFailure
public static TestFailure createTestFailure(Element testCaseElement, Element failureElement, String defaultType) Creates aTestFailureinstance by extracting relevant failure information from a JUnit XML test case element and its associated failure element.- Parameters:
testCaseElement- The XML element representing the test case.failureElement- The XML element representing the test failuredefaultType- The default failure type to use if the type is not specified in the failure element.- Returns:
- A
TestFailureobject containing the extracted failure details
-
extractDisplayName
Extracts the display-name from the system-out element within a test case.- Parameters:
testCaseElement- The test case element to search within- Returns:
- The display name if found, or empty if not present
-
extractTestFailuresGrouped
Extracts test failure information from a JUnit XML report and groups by class name.- Parameters:
xmlFilePath- Path to the JUnit XML file- Returns:
- Map of class names to
TestClassFailuresobjects containing grouped failures - Throws:
JUnitXmlParserException- if parsing fails or the file doesn't exist
-
getAttributeOrDefault
public static String getAttributeOrDefault(Element element, String attributeName, String defaultValue) Retrieves the value of a specified attribute from the provided XML element.- Parameters:
element- The XML element from which to retrieve the attributeattributeName- The name of the attribute to retrievedefaultValue- The default value to return if the attribute is absent or blank- Returns:
- The value of the attribute if present and non-blank; otherwise, the default value
-
getTextContentTrimmed
Retrieves the trimmed text content of the specified XML element.- Parameters:
element- The XML element from which to extract and trim the text content- Returns:
- The trimmed text content of the element
-
parseTestCases
Parses a list of test case nodes from a JUnit XML report and groups the failures by their respective test class names.- Parameters:
testCases- The list of test case nodes to parse
-
parseTime
Parses a time value represented as aStringand returns its numeric equivalent.- Parameters:
timeStr- The time value as a string to be parsed- Returns:
- The parsed time value as a double, or
0.0if the input is invalid
-
validateFile
Validates file existence and readability.- Throws:
JUnitXmlParserException- if the file does not exist or is not readable
-