Class JUnitXmlParser

java.lang.Object
rife.bld.extension.junitreporter.JUnitXmlParser

public final class JUnitXmlParser extends Object
Utility class to parse JUnit XML reports.
Since:
1.0
Author:
Erik C. Thauvin
  • Field Details

  • Method Details

    • createTestFailure

      public static TestFailure createTestFailure(Element testCaseElement, Element failureElement, String defaultType)
      Creates a TestFailure instance 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 failure
      defaultType - The default failure type to use if the type is not specified in the failure element.
      Returns:
      A TestFailure object containing the extracted failure details
    • extractDisplayName

      public static String extractDisplayName(Element testCaseElement)
      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

      public static Map<String,TestClassFailures> extractTestFailuresGrouped(String xmlFilePath)
      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 TestClassFailures objects 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 attribute
      attributeName - The name of the attribute to retrieve
      defaultValue - 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

      public static String getTextContentTrimmed(Element element)
      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

      public 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.
      Parameters:
      testCases - The list of test case nodes to parse
    • parseTime

      public static double parseTime(String timeStr)
      Parses a time value represented as a String and 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.0 if the input is invalid
    • validateFile

      public static void validateFile(Path path) throws JUnitXmlParserException
      Validates file existence and readability.
      Throws:
      JUnitXmlParserException - if the file does not exist or is not readable