Class JUnitBridgeListener

java.lang.Object
io.karatelabs.junit6.JUnitBridgeListener
All Implemented Interfaces:
io.karatelabs.output.ResultListener

public class JUnitBridgeListener extends Object implements io.karatelabs.output.ResultListener
Bridges Karate execution events to JUnit's dynamic test tree via a blocking queue.

Implements ResultListener to receive streaming events from Karate execution and converts them to TestEvent records that are consumed by StreamingTestIterator on the JUnit thread.

Supports two modes:

  • Flat mode: All scenarios appear at the root level
  • Hierarchical mode: Features as containers with scenario children
  • Constructor Summary

    Constructors
    Constructor
    Description
    JUnitBridgeListener(BlockingQueue<TestEvent> eventQueue, boolean hierarchical)
    Creates a new bridge listener.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    complete(io.karatelabs.core.SuiteResult result)
    Signals that the suite has fully finished, terminating the stream.
    void
    onFeatureEnd(io.karatelabs.core.FeatureResult result)
     
    void
    onFeatureStart(io.karatelabs.gherkin.Feature feature)
     
    void
    onScenarioEnd(io.karatelabs.core.ScenarioResult result)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.karatelabs.output.ResultListener

    onScenarioStart, onSuiteEnd, onSuiteStart
  • Constructor Details

    • JUnitBridgeListener

      public JUnitBridgeListener(BlockingQueue<TestEvent> eventQueue, boolean hierarchical)
      Creates a new bridge listener.
      Parameters:
      eventQueue - the queue to publish events to
      hierarchical - if true, emit FeatureStart/FeatureEnd events for container nesting
  • Method Details

    • onFeatureStart

      public void onFeatureStart(io.karatelabs.gherkin.Feature feature)
      Specified by:
      onFeatureStart in interface io.karatelabs.output.ResultListener
    • onFeatureEnd

      public void onFeatureEnd(io.karatelabs.core.FeatureResult result)
      Specified by:
      onFeatureEnd in interface io.karatelabs.output.ResultListener
    • onScenarioEnd

      public void onScenarioEnd(io.karatelabs.core.ScenarioResult result)
      Specified by:
      onScenarioEnd in interface io.karatelabs.output.ResultListener
    • complete

      public void complete(io.karatelabs.core.SuiteResult result)
      Signals that the suite has fully finished, terminating the stream.

      Deliberately not driven by ResultListener.onSuiteEnd(SuiteResult): that callback fires while the suite is still running its listener chain, so report writers (JUnit XML, Cucumber JSON) registered after this bridge may not have flushed their asynchronous per-feature writes yet. Emitting the terminal event from here — invoked only once Runner.Builder.parallel(...) has fully returned — guarantees that when the JUnit @TestFactory stream completes, all report files are on disk.

      Parameters:
      result - the suite result (may be null if execution failed before completing)