ZIO Test SBT Framework integration that provides test interface implementation for running ZIO-based tests within SBT build environments
—
Full-featured JVM test runner with advanced debugging capabilities, signal handling, and comprehensive SBT integration features. This provides the most complete ZIO Test SBT integration experience.
The primary JVM test runner that provides full-featured test execution with advanced debugging and development features.
/**
* JVM-specific test runner with full SBT integration
* Provides advanced debugging, signal handling, and comprehensive test execution
*/
final class ZTestRunnerJVM(
val args: Array[String],
val remoteArgs: Array[String],
testClassLoader: ClassLoader
) extends Runner {
/** Test output renderer (mutable for configuration) */
var renderer: TestRenderer
/** Optional shutdown hook for cleanup (mutable) */
var shutdownHook: Option[() => Unit]
/** Thread-safe storage for test summaries */
val summaries: AtomicReference[Vector[Summary]]
/**
* Create test tasks from discovered test definitions
* @param defs Array of SBT task definitions
* @return Array of executable test tasks
*/
def tasks(defs: Array[TaskDef]): Array[Task]
/**
* Complete test execution and return formatted results
* Handles summary aggregation, result formatting, and cleanup
* @return Formatted test results string
*/
def done(): String
/**
* Create summary sender for test result collection
* @param trace Implicit trace for ZIO effect tracking
* @return SendSummary effect for collecting test results
*/
def sendSummary(implicit trace: Trace): SendSummary
/**
* Internal method for creating test tasks with full ZIO integration
* @param defs Array of SBT task definitions
* @param console ZIO Console service
* @param trace Implicit trace for effect tracking
* @return Array of ZTestTask instances with full type information
*/
private[sbt] def tasksZ(
defs: Array[TaskDef],
console: zio.Console
)(implicit trace: Trace): Array[ZTestTask[TestOutput]]
}JVM-specific test task implementation with signal handler support and enhanced debugging capabilities.
/**
* JVM-specific test task with signal handler support
* Provides enhanced debugging and development features
*/
final class ZTestTask[T](
taskDef: TaskDef,
testClassLoader: ClassLoader,
sendSummary: SendSummary,
testArgs: TestArgs,
spec: ZIOSpecAbstract,
runtime: zio.Runtime[T],
console: zio.Console
) extends BaseTestTask(taskDef, testClassLoader, sendSummary, testArgs, spec, runtime, console) {
/**
* Run test with signal handler installation
* Provides fiber dumping on system signals for debugging
* @param eventHandlerZ ZIO test event handler
* @param trace Implicit trace for effect tracking
* @return ZIO effect for test execution
*/
private[zio] def run(eventHandlerZ: ZTestEventHandler)(implicit trace: Trace): ZIO[Any, Throwable, Unit]
/**
* Install signal handlers for debugging support
* Provides fiber dumping capabilities on system signals
* @param trace Implicit trace for effect tracking
*/
private def installSignalHandlers()(implicit trace: Trace): Unit
}Factory methods for creating JVM test tasks.
object ZTestTask {
/** Thread-safe flag for signal handler installation */
private val installedSignals: AtomicBoolean
/**
* Create a JVM test task instance
* @param taskDef SBT task definition
* @param testClassLoader ClassLoader for loading test classes
* @param sendSummary Summary collection effect
* @param args Parsed test arguments
* @param runtime ZIO runtime for test execution
* @param console Console service for output
* @return Configured ZTestTask instance
*/
def apply[T](
taskDef: TaskDef,
testClassLoader: ClassLoader,
sendSummary: SendSummary,
args: TestArgs,
runtime: zio.Runtime[T],
console: zio.Console
): ZTestTask[T]
}Signal Handler Support:
The JVM runner installs signal handlers for debugging support:
// Installs signal handlers for fiber dumping
private def installSignalHandlers()(implicit trace: Trace): Unit = {
val dumpFibers = () => Runtime.default.unsafe.run(Fiber.dumpAll)
if (System.os.isWindows) {
Platform.addSignalHandler("INT", dumpFibers) // Ctrl+C on Windows
} else {
Platform.addSignalHandler("INFO", dumpFibers) // SIGINFO on Unix
Platform.addSignalHandler("USR1", dumpFibers) // SIGUSR1 on Unix
}
}Runtime Management:
// Creates scoped runtime with proper lifecycle management
val runtime: Runtime.Scoped[TestOutput] =
zio.Runtime.unsafe.fromLayer(sharedLayer)(Trace.empty, Unsafe.unsafe)
// Registers shutdown hook for cleanup
shutdownHook = Some(() => runtime.unsafe.shutdown()(Unsafe.unsafe))Test Argument Processing:
// Parses and processes test arguments
val testArgs = TestArgs.parse(args)
// Configures renderer based on arguments
renderer = testArgs.testRenderer
// Creates shared output layer for all tests
val sharedTestOutputLayer = ExecutionEventPrinter.live(console, testArgs.testEventRenderer) >>> TestOutput.liveTaskDef instances to ZTestTask instancesThe JVM runner provides comprehensive summary processing:
def done(): String = {
val allSummaries = summaries.get
val total = allSummaries.map(_.total).sum
val ignore = allSummaries.map(_.ignore).sum
val compositeSummary = allSummaries.foldLeft(Summary.empty)(_.add(_))
val renderedSummary = renderer.renderSummary(compositeSummary)
val renderedResults =
if (allSummaries.nonEmpty && total != ignore)
colored(renderedSummary)
else if (ignore > 0)
s"${Console.YELLOW}All eligible tests are currently ignored ${Console.RESET}"
else
s"${Console.YELLOW}No tests were executed${Console.RESET}"
// Print results directly to work around SBT forked JVM issues
if (allSummaries.nonEmpty) println(renderedResults)
shutdownHook.foreach(_.apply())
"Completed tests"
}The JVM platform provides several advantages:
Install with Tessl CLI
npx tessl i tessl/maven-dev-zio--zio-test-sbt-3