or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cross-platform.mdevent-reporting.mdframework.mdindex.mdtask-execution.md

task-execution.mddocs/

0

# Task Execution

1

2

The task execution system handles the running of individual ZIO Test specifications within SBT's testing infrastructure.

3

4

## BaseTestTask

5

6

Abstract base class for executing ZIO Test specifications as SBT tasks.

7

8

```scala { .api }

9

abstract class BaseTestTask(

10

taskDef: TaskDef,

11

testClassLoader: ClassLoader,

12

sendSummary: SendSummary,

13

args: TestArgs

14

) extends Task {

15

final def taskDef(): TaskDef

16

def execute(eventHandler: EventHandler, loggers: Array[Logger]): Array[Task]

17

def tags(): Array[String]

18

}

19

```

20

21

### Constructor Parameters

22

23

- `taskDef: TaskDef` - SBT task definition containing test metadata

24

- `testClassLoader: ClassLoader` - Class loader for loading test specifications

25

- `sendSummary: SendSummary` - Effect for sending test result summaries

26

- `args: TestArgs` - Parsed command line test arguments

27

28

### Properties and Methods

29

30

#### taskDef()

31

32

Returns the SBT task definition.

33

34

**Returns:** `TaskDef` - The task definition passed to the constructor

35

36

#### execute()

37

38

Executes the test task and reports results.

39

40

**Parameters:**

41

- `eventHandler: EventHandler` - SBT event handler for reporting test events

42

- `loggers: Array[Logger]` - SBT loggers for test output

43

44

**Returns:** `Array[Task]` - Array of follow-up tasks (typically empty)

45

46

#### tags()

47

48

Returns test tags for filtering.

49

50

**Returns:** `Array[String]` - Empty array (no tags supported)

51

52

### Protected Members

53

54

```scala { .api }

55

// Available to subclasses

56

protected lazy val specInstance: AbstractRunnableSpec

57

protected def run(eventHandler: EventHandler): ZIO[TestLogger with Clock, Throwable, Unit]

58

protected def sbtTestLayer(loggers: Array[Logger]): Layer[Nothing, TestLogger with Clock]

59

```

60

61

## Platform-Specific Implementations

62

63

### ZTestTask (JVM)

64

65

Simple implementation that extends `BaseTestTask` directly.

66

67

```scala { .api }

68

class ZTestTask(

69

taskDef: TaskDef,

70

testClassLoader: ClassLoader,

71

sendSummary: SendSummary,

72

testArgs: TestArgs

73

) extends BaseTestTask(taskDef, testClassLoader, sendSummary, testArgs)

74

```

75

76

### ZTestTask (JavaScript/Native)

77

78

Asynchronous implementation with continuation support.

79

80

```scala { .api }

81

class ZTestTask(

82

taskDef: TaskDef,

83

testClassLoader: ClassLoader,

84

runnerType: String,

85

sendSummary: SendSummary,

86

testArgs: TestArgs

87

) extends BaseTestTask(taskDef, testClassLoader, sendSummary, testArgs) {

88

def execute(

89

eventHandler: EventHandler,

90

loggers: Array[Logger],

91

continuation: Array[Task] => Unit

92

): Unit

93

}

94

```

95

96

**Additional Parameters:**

97

- `runnerType: String` - Type of runner ("master" or "slave")

98

- `continuation: Array[Task] => Unit` - Callback for asynchronous completion

99

100

## Task Management

101

102

### ZTestRunner Task Creation

103

104

Test runners create tasks from SBT task definitions:

105

106

```scala { .api }

107

// JVM implementation

108

class ZTestRunner extends Runner {

109

def tasks(defs: Array[TaskDef]): Array[Task] = {

110

val testArgs = TestArgs.parse(args)

111

val tasks = defs.map(new ZTestTask(_, testClassLoader, sendSummary, testArgs))

112

// Apply task policy

113

val taskPolicy = loadTaskPolicy(testArgs.testTaskPolicy)

114

taskPolicy.merge(tasks)

115

}

116

}

117

```

118

119

### Task Policy

120

121

Strategy pattern for merging multiple test tasks.

122

123

```scala { .api }

124

abstract class ZTestTaskPolicy {

125

def merge(zioTasks: Array[ZTestTask]): Array[Task]

126

}

127

128

class ZTestTaskPolicyDefaultImpl extends ZTestTaskPolicy {

129

def merge(zioTasks: Array[ZTestTask]): Array[Task] = zioTasks.toArray

130

}

131

```

132

133

## SendSummary

134

135

Type alias and utilities for sending test result summaries.

136

137

```scala { .api }

138

type SendSummary = URIO[Summary, Unit]

139

140

object SendSummary {

141

def fromSend(send: Summary => Unit): SendSummary

142

def fromSendM(send: Summary => UIO[Unit]): SendSummary

143

def noop: SendSummary

144

}

145

```

146

147

### Methods

148

149

#### fromSend()

150

151

Creates a `SendSummary` from a synchronous function.

152

153

**Parameters:**

154

- `send: Summary => Unit` - Function to send summary

155

156

**Returns:** `SendSummary` - ZIO effect that calls the function

157

158

#### fromSendM()

159

160

Creates a `SendSummary` from an effectful function.

161

162

**Parameters:**

163

- `send: Summary => UIO[Unit]` - Effectful function to send summary

164

165

**Returns:** `SendSummary` - ZIO effect that executes the function

166

167

#### noop

168

169

No-operation implementation that does nothing.

170

171

**Returns:** `SendSummary` - Effect that completes successfully without action

172

173

## Usage Example

174

175

```scala

176

// Task execution is handled internally by SBT

177

// The framework creates tasks and executes them:

178

179

val taskDef = // ... created by SBT

180

val task = new ZTestTask(taskDef, classLoader, sendSummary, testArgs)

181

182

// SBT calls execute to run the test

183

val followUpTasks = task.execute(eventHandler, loggers)

184

```