Class JunitXmlWriter

java.lang.Object
io.karatelabs.output.JunitXmlWriter

public final class JunitXmlWriter extends Object
Generates JUnit XML reports compatible with CI systems (Jenkins, GitHub Actions, etc.).

Output follows the standard JUnit XML schema with per-feature files:

 <testsuite name="feature" tests="N" failures="N" time="secs">
   <testcase name="scenario" classname="feature.path" time="secs">
     <properties>
       <property name="tags" value="@smoke,@api"/>
       <property name="requirements" value="REQ-1,REQ-2"/>
     </properties>
     <system-out>step logs</system-out>
     <failure message="error">stacktrace</failure>
   </testcase>
 </testsuite>
 
  • Method Details

    • serializeFeature

      public static String serializeFeature(FeatureResult result)
      Serialize a feature result to its XML text.

      Separated from the file write so a listener can do this synchronously, while the result is still whole. The suite releases nested karate.call() trees once a feature's listeners have returned, and this output flattens called features' steps into its own — so serializing on a background thread would silently drop them.

    • fileNameFor

      public static String fileNameFor(FeatureResult result)
      File name this feature's output is written under.
    • writeSerialized

      public static void writeSerialized(String fileName, String content, Path outputDir)
      Write pre-serialized content. Safe after the source result has been released.
    • writeFeature

      public static void writeFeature(FeatureResult result, Path outputDir)
    • featureToXml

      public static String featureToXml(FeatureResult result)
      Convert a single feature result to JUnit XML string.
      Parameters:
      result - the feature result
      Returns:
      XML string