CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-zio--zio-test-sbt-3

ZIO Test SBT Framework integration that provides test interface implementation for running ZIO-based tests within SBT build environments

Pending
Overview
Eval results
Files

test-discovery.mddocs/

Test Discovery

Test specification discovery mechanism that allows SBT to identify ZIO test classes and convert them into executable test tasks. This system enables automatic detection of ZIO test specifications in the classpath.

Capabilities

ZioSpecFingerprint

The fingerprint implementation that enables SBT to discover ZIO test specifications by identifying classes that extend ZIOSpecAbstract.

/**
 * SBT fingerprint for discovering ZIO test specifications
 * Identifies classes extending ZIOSpecAbstract as test targets
 */
object ZioSpecFingerprint extends SubclassFingerprint {
  /**
   * Returns the superclass name that SBT should look for
   * @return Fully qualified name of ZIOSpecAbstract class
   */
  def superclassName(): String
  
  /**
   * Indicates that test specifications are module objects (Scala objects)
   * @return Always true, as ZIO tests are typically defined as objects
   */
  def isModule(): Boolean
  
  /**
   * Indicates whether a no-argument constructor is required
   * @return Always false, as Scala objects don't require explicit constructors
   */
  def requireNoArgConstructor(): Boolean
}

Implementation Details:

// Returns the ZIOSpecAbstract class name for discovery
def superclassName(): String = classOf[ZIOSpecAbstract].getName

// ZIO test specifications are typically Scala objects
final def isModule(): Boolean = true

// Scala objects don't require no-arg constructors
final def requireNoArgConstructor(): Boolean = false

Discovery Process

The test discovery process follows this flow:

  1. Classpath Scanning: SBT scans the test classpath for classes matching the fingerprint criteria
  2. Subclass Detection: Identifies all classes/objects extending ZIOSpecAbstract
  3. Module Loading: Loads Scala objects (modules) that contain test specifications
  4. Task Creation: Converts discovered specifications into executable TaskDef instances
  5. Runner Delegation: Passes TaskDef instances to platform-specific test runners

Supported Test Patterns

The fingerprint discovers various ZIO test specification patterns:

Basic ZIO Spec Object:

object MyTestSpec extends ZIOSpecDefault {
  def spec = suite("MyTests")(
    test("example test") {
      assert(1 + 1)(equalTo(2))
    }
  )
}

Custom ZIO Spec:

object CustomSpec extends ZIOSpec[TestEnvironment] {
  def spec = suite("CustomTests")(
    test("custom test") {
      // test implementation
      assertTrue(true)
    }
  )
}

ZIO Spec with Environment:

object DatabaseSpec extends ZIOSpecDefault {
  override def spec = suite("DatabaseTests")(
    test("database connection") {
      // test with custom environment
      assertTrue(true)
    }
  ).provide(/* custom layers */)
}

Integration with SBT

The fingerprint integrates seamlessly with SBT's test discovery mechanism:

// SBT uses the fingerprint to:
// 1. Scan classpath for matching classes
// 2. Create TaskDef instances for each discovered test
// 3. Pass TaskDefs to the framework's runner
// 4. Execute tests and collect results

val discoveredSpecs: Array[TaskDef] = sbtDiscoveryEngine.discover(ZioSpecFingerprint)
val runner = framework.runner(args, remoteArgs, classLoader)
val tasks = runner.tasks(discoveredSpecs)

Platform Considerations

The fingerprint works consistently across all supported platforms:

  • JVM: Full reflection-based class discovery and loading
  • JavaScript: Uses portable reflection for module loading
  • Native: Optimized reflection for native compilation constraints

Error Handling

The discovery process handles various error conditions:

  • Missing Classes: Gracefully handles cases where discovered classes cannot be loaded
  • Invalid Specifications: Filters out classes that don't properly extend ZIOSpecAbstract
  • ClassLoader Issues: Manages class loading failures with appropriate error reporting

The robust discovery mechanism ensures that ZIO test specifications are reliably found and executed across different build configurations and runtime environments.

Install with Tessl CLI

npx tessl i tessl/maven-dev-zio--zio-test-sbt-3

docs

event-handling.md

framework-integration.md

index.md

js-platform.md

jvm-platform.md

native-platform.md

test-discovery.md

tile.json