0
# Configuration
1
2
Configure property-based test execution with comprehensive parameter control including test counts, generator sizes, random seeds, verbosity levels, and parallel execution. The configuration system supports both programmatic setup and command-line parameter overrides for flexible test environments.
3
4
## Capabilities
5
6
### Parameter Configuration
7
8
Configure test execution parameters with builder methods for both quiet and verbose test runs.
9
10
```scala { .api }
11
trait ScalaCheckParameters {
12
implicit def defaultParameters: Parameters
13
implicit def defaultFreqMapPretty: FreqMap[Set[Any]] => Pretty
14
15
def set(
16
minTestsOk: Int = defaultParameters.minTestsOk,
17
minSize: Int = defaultParameters.minSize,
18
maxDiscardRatio: Float = defaultParameters.maxDiscardRatio,
19
maxSize: Int = defaultParameters.maxSize,
20
workers: Int = defaultParameters.workers,
21
callback: Test.TestCallback = defaultParameters.testCallback,
22
loader: Option[ClassLoader] = defaultParameters.loader
23
): Parameters
24
25
def display(
26
minTestsOk: Int = defaultParameters.minTestsOk,
27
minSize: Int = defaultParameters.minSize,
28
maxDiscardRatio: Float = defaultParameters.maxDiscardRatio,
29
maxSize: Int = defaultParameters.maxSize,
30
workers: Int = defaultParameters.workers,
31
callback: Test.TestCallback = defaultParameters.testCallback,
32
loader: Option[ClassLoader] = defaultParameters.loader
33
): Parameters
34
}
35
```
36
37
**Usage:**
38
```scala
39
import org.specs2._
40
import org.specs2.ScalaCheck
41
42
class ConfiguredSpec extends Specification with ScalaCheck { def is = s2"""
43
High volume testing ${
44
prop((xs: List[Int]) => xs.reverse.reverse == xs)
45
.set(minTestsOk = 1000, maxSize = 200)
46
}
47
48
Verbose testing ${
49
prop((s: String) => s.length >= 0)
50
.display(minTestsOk = 50)
51
}
52
"""
53
}
54
```
55
56
### Parameters Case Class
57
58
Encapsulate all ScalaCheck and specs2-specific test parameters with conversion and override capabilities.
59
60
```scala { .api }
61
case class Parameters(
62
minTestsOk: Int = Test.Parameters.default.minSuccessfulTests,
63
minSize: Int = Test.Parameters.default.minSize,
64
maxDiscardRatio: Float = Test.Parameters.default.maxDiscardRatio,
65
maxSize: Int = Test.Parameters.default.maxSize,
66
workers: Int = Test.Parameters.default.workers,
67
testCallback: Test.TestCallback = Test.Parameters.default.testCallback,
68
loader: Option[ClassLoader] = Test.Parameters.default.customClassLoader,
69
prettyParams: Pretty.Params = Pretty.defaultParams,
70
seed: Option[Seed] = None
71
) {
72
def verbose: Parameters
73
def setVerbosity(v: Int): Parameters
74
def testParameters: Test.Parameters
75
def overrideWith(commandLine: CommandLine): Parameters
76
}
77
```
78
79
**Usage:**
80
```scala
81
// Custom parameters instance
82
implicit val customParams = Parameters(
83
minTestsOk = 500,
84
maxSize = 100,
85
workers = 4,
86
seed = Some(Seed.fromBase64("custom-seed").get)
87
).verbose
88
89
class ParameterizedSpec extends Specification with ScalaCheck { def is = s2"""
90
Parameterized property ${prop((n: Int) => n * n >= 0)}
91
"""
92
}
93
```
94
95
### Seed Management
96
97
Control random seed generation for reproducible test runs and debugging failed properties.
98
99
```scala { .api }
100
object Parameters {
101
def makeSeed(seed: String): Option[Seed]
102
}
103
104
// In ScalaCheckProperty
105
trait ScalaCheckProperty {
106
def setSeed(seed: Seed): SelfType
107
def setSeed(seed: String): SelfType
108
}
109
```
110
111
**Usage:**
112
```scala
113
class ReproducibleSpec extends Specification with ScalaCheck { def is = s2"""
114
Reproducible property ${
115
prop((data: List[String]) => processData(data).size <= data.size)
116
.setSeed("AbCdEf1234567890") // Base64 encoded seed
117
}
118
119
Debug failing property ${
120
prop((x: Double) => x + 0.0 == x)
121
.setSeed(Seed.fromBase64("failing-test-seed").get)
122
.verbose
123
}
124
"""
125
}
126
```
127
128
### Verbosity Control
129
130
Control test output verbosity for debugging and monitoring test execution.
131
132
```scala { .api }
133
trait ScalaCheckProperty {
134
def setVerbosity(v: Int): SelfType
135
def verbose: SelfType
136
}
137
138
case class Parameters(...) {
139
def verbose: Parameters
140
def setVerbosity(v: Int): Parameters
141
}
142
```
143
144
**Usage:**
145
```scala
146
class VerboseSpec extends Specification with ScalaCheck { def is = s2"""
147
Debug property ${
148
prop((input: ComplexData) => validateComplexData(input))
149
.verbose
150
.set(minTestsOk = 10) // Fewer tests but verbose output
151
}
152
153
Custom verbosity ${
154
prop((xs: List[Int]) => xs.sorted.head <= xs.sorted.last)
155
.setVerbosity(2) // Higher verbosity level
156
}
157
"""
158
}
159
```
160
161
### Command Line Integration
162
163
Override parameters from command line arguments for flexible test execution in different environments.
164
165
```scala { .api }
166
case class Parameters(...) {
167
def overrideWith(commandLine: CommandLine): Parameters
168
}
169
```
170
171
**Command line options:**
172
- `scalacheck.mintestsok=N` - Minimum successful tests
173
- `scalacheck.minsize=N` - Minimum generator size
174
- `scalacheck.maxdiscardratio=F` - Maximum discard ratio
175
- `scalacheck.maxsize=N` - Maximum generator size
176
- `scalacheck.workers=N` - Number of worker threads
177
- `scalacheck.seed=BASE64` - Random seed (Base64 encoded)
178
- `scalacheck.verbosity=N` - Verbosity level
179
- `scalacheck.verbose=true` - Enable verbose mode
180
181
## Types
182
183
```scala { .api }
184
// Parameter configuration trait
185
trait ScalaCheckParameters {
186
implicit def defaultParameters: Parameters
187
implicit def defaultFreqMapPretty: FreqMap[Set[Any]] => Pretty
188
def set(...): Parameters
189
def display(...): Parameters
190
}
191
192
// Parameters case class
193
case class Parameters(
194
minTestsOk: Int,
195
minSize: Int,
196
maxDiscardRatio: Float,
197
maxSize: Int,
198
workers: Int,
199
testCallback: Test.TestCallback,
200
loader: Option[ClassLoader],
201
prettyParams: Pretty.Params,
202
seed: Option[Seed]
203
) {
204
def verbose: Parameters
205
def setVerbosity(v: Int): Parameters
206
def testParameters: Test.Parameters
207
def overrideWith(commandLine: CommandLine): Parameters
208
}
209
210
// Parameters companion
211
object Parameters {
212
def makeSeed(seed: String): Option[Seed]
213
}
214
```