ZIO Test SBT Framework integration that provides test interface implementation for running ZIO-based tests within SBT build environments
—
Event conversion and handling system that translates ZIO test execution events into SBT's event format for proper reporting and integration with build tools and IDEs.
SBT event implementation that represents the results of ZIO test execution, providing all necessary information for test reporting and IDE integration.
/**
* SBT event implementation for ZIO test results
* Converts ZIO test execution results into SBT's event format
*/
final case class ZTestEvent(
fullyQualifiedName0: String,
selector0: Selector,
status0: Status,
maybeThrowable: Option[Throwable],
duration0: Long,
fingerprint0: Fingerprint
) extends Event {
/** Get test execution duration in milliseconds */
def duration(): Long
/** Get test fingerprint for identification */
def fingerprint(): Fingerprint
/** Get fully qualified name of test class */
def fullyQualifiedName(): String
/** Get test selector identifying specific test case */
def selector(): Selector
/** Get test execution status (Success, Failure, Ignored, etc.) */
def status(): Status
/** Get optional throwable for failed tests, wrapped in OptionalThrowable */
def throwable(): OptionalThrowable
}Factory methods for creating SBT events from ZIO test execution results.
object ZTestEvent {
/**
* Converts ZIO test execution event to SBT event
* @param test ZIO test execution event containing results
* @param taskDef SBT task definition for the test
* @param renderer Test result renderer for formatting failure messages
* @return SBT Event instance for reporting
*/
def convertEvent(test: ExecutionEvent.Test[_], taskDef: TaskDef, renderer: TestRenderer): Event
/**
* Converts ZIO test result to SBT status
* @param test ZIO test execution event
* @return SBT Status (Success, Failure, Ignored)
*/
private def statusFrom(test: ExecutionEvent.Test[_]): Status
}Usage Example:
// Convert ZIO test event to SBT event
val sbtEvent = ZTestEvent.convertEvent(zioTestEvent, taskDef, renderer)
// The converted event contains:
// - Test name and selector for identification
// - Success/failure status with optional failure details
// - Execution duration for performance reporting
// - Formatted failure messages with ANSI colors for terminal displayEvent handler that processes ZIO test execution events and reports them to SBT's event handling system.
/**
* Handles ZIO test events and reports to SBT
* Ensures proper test result reporting and build failure detection
*/
class ZTestEventHandlerSbt(
eventHandler: EventHandler,
taskDef: TaskDef,
renderer: TestRenderer
) extends ZTestEventHandler {
/** Semaphore for thread-safe event handling */
val semaphore: Semaphore
/**
* Process execution events and report to SBT
* @param event ZIO test execution event to handle
* @return ZIO effect for event processing
*/
def handle(event: ExecutionEvent): UIO[Unit]
}The event handler processes different types of ZIO test events:
Test Execution Events:
// Handles completed test cases (success, failure, ignored)
case ExecutionEvent.Test(_, _, _, _, _, _, _) =>
val zTestEvent = ZTestEvent.convertEvent(evt, taskDef, renderer)
semaphore.withPermit(ZIO.succeed(eventHandler.handle(zTestEvent)))Runtime Failure Events:
// Handles runtime failures (exceptions, fiber failures, etc.)
case ExecutionEvent.RuntimeFailure(_, _, failure, _) =>
val zTestEvent = ZTestEvent(
taskDef.fullyQualifiedName(),
taskDef.selectors().head,
Status.Failure,
cause.dieOption,
annotations.get(TestAnnotation.timing).toMillis,
ZioSpecFingerprint
)
semaphore.withPermit(ZIO.succeed(eventHandler.handle(zTestEvent)))Other Events:
// These events are processed but don't generate SBT events
case ExecutionEvent.TestStarted(_, _, _, _, _) => ZIO.unit
case ExecutionEvent.SectionStart(_, _, _) => ZIO.unit
case ExecutionEvent.SectionEnd(_, _, _) => ZIO.unit
case ExecutionEvent.TopLevelFlush(_) => ZIO.unitZIO test results are converted to SBT status values:
// Success cases
case Right(TestSuccess.Succeeded(_)) => Status.Success
// Ignored/skipped tests
case Right(TestSuccess.Ignored(_)) => Status.Ignored
// Failed tests (assertions, exceptions, etc.)
case Left(_) => Status.FailureFailed tests include formatted failure messages with ANSI colors:
val status = statusFrom(test)
val maybeThrowable = status match {
case Status.Failure =>
// Includes ANSI colors for terminal display
val failureMsg = renderer
.render(test, true)
.mkString("\n")
Some(new Exception(failureMsg))
case _ => None
}Event handling is thread-safe through semaphore-based synchronization:
// Ensures only one event is processed at a time
val semaphore = Semaphore.unsafe.make(1L)(Unsafe.unsafe)
// All event handling goes through the semaphore
semaphore.withPermit(ZIO.succeed(eventHandler.handle(zTestEvent)))The event handling system provides:
Install with Tessl CLI
npx tessl i tessl/maven-dev-zio--zio-test-sbt-3