0
# Framework Integration
1
2
Core framework classes that integrate ZIO Test with SBT's test discovery and execution system. These classes implement the standard SBT test interface to enable SBT to recognize and execute ZIO test specifications.
3
4
## Capabilities
5
6
### ZTestFramework
7
8
Main framework entry point that SBT uses to recognize ZIO Test as a legitimate test framework.
9
10
```scala { .api }
11
/**
12
* Main framework entry point for SBT integration
13
* Implements sbt.testing.Framework interface
14
*/
15
class ZTestFramework extends Framework {
16
/** Framework display name with ANSI formatting */
17
val name: String = s"${Console.UNDERLINED}ZIO Test${Console.RESET}"
18
19
/** Array of fingerprints for test discovery */
20
val fingerprints: Array[Fingerprint] = Array(ZioSpecFingerprint)
21
22
/** Creates appropriate platform-specific runner */
23
def runner(
24
args: Array[String],
25
remoteArgs: Array[String],
26
testClassLoader: ClassLoader
27
): Runner
28
}
29
```
30
31
The framework creates platform-specific runners:
32
- **JVM**: Returns `ZTestRunnerJVM` for full-featured JVM execution
33
- **JavaScript**: Returns `ZMasterTestRunnerJS` for browser/Node.js execution
34
- **Scala Native**: Returns `ZMasterTestRunner` for native binary execution
35
36
**Usage Example:**
37
38
```scala
39
// Configured automatically in build.sbt
40
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
41
```
42
43
### ZioSpecFingerprint
44
45
Fingerprint that tells SBT how to discover ZIO test classes by identifying classes that extend `ZIOSpecAbstract`.
46
47
```scala { .api }
48
/**
49
* Fingerprint for ZIO test discovery
50
* Extends sbt.testing.SubclassFingerprint
51
*/
52
object ZioSpecFingerprint extends SubclassFingerprint {
53
/** Returns the superclass name for test discovery */
54
def superclassName(): String = classOf[ZIOSpecAbstract].getName
55
56
/** Indicates tests are objects/modules, not classes */
57
def isModule(): Boolean = true
58
59
/** ZIO specs don't require no-arg constructors */
60
def requireNoArgConstructor(): Boolean = false
61
}
62
```
63
64
This fingerprint enables SBT to automatically discover any Scala object that extends `ZIOSpecAbstract`, `ZIOSpecDefault`, or other ZIO test base classes.
65
66
**Usage Example:**
67
68
```scala
69
// This object will be discovered by SBT automatically
70
object MyTestSpec extends ZIOSpecDefault {
71
def spec = suite("My Tests")(
72
test("example") {
73
assertTrue(true)
74
}
75
)
76
}
77
```
78
79
### Framework Registration
80
81
The framework must be registered in your build configuration for SBT to use it.
82
83
**SBT Configuration:**
84
85
```scala
86
// build.sbt
87
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
88
libraryDependencies += "dev.zio" %% "zio-test-sbt" % "2.1.19" % Test
89
```
90
91
**Mill Configuration:**
92
93
```scala
94
// build.sc
95
def testFramework = Seq("zio.test.sbt.ZTestFramework")
96
def ivyDeps = Agg(ivy"dev.zio::zio-test-sbt:2.1.19")
97
```
98
99
### Cross-Platform Framework Variations
100
101
The framework implementation varies slightly across platforms to support platform-specific features:
102
103
**JavaScript Platform:**
104
```scala { .api }
105
class ZTestFramework extends Framework {
106
// Creates ZMasterTestRunnerJS for local execution
107
def runner(
108
args: Array[String],
109
remoteArgs: Array[String],
110
testClassLoader: ClassLoader
111
): ZMasterTestRunnerJS
112
113
// Creates ZSlaveTestRunnerJS for distributed execution
114
def slaveRunner(
115
args: Array[String],
116
remoteArgs: Array[String],
117
testClassLoader: ClassLoader,
118
send: String => Unit
119
): ZSlaveTestRunnerJS
120
}
121
```
122
123
**Scala Native Platform:**
124
```scala { .api }
125
class ZTestFramework extends Framework {
126
// Creates ZMasterTestRunner for local execution
127
def runner(
128
args: Array[String],
129
remoteArgs: Array[String],
130
testClassLoader: ClassLoader
131
): ZMasterTestRunner
132
133
// Creates ZSlaveTestRunner for distributed execution
134
def slaveRunner(
135
args: Array[String],
136
remoteArgs: Array[String],
137
testClassLoader: ClassLoader,
138
send: String => Unit
139
): ZSlaveTestRunner
140
}
141
```
142
143
The slave runner functionality enables running tests in separate processes or workers, which is particularly useful for JavaScript and Native platforms where memory isolation or parallelization across processes is beneficial.