specs2-scalacheck provides integration between the specs2 testing framework and ScalaCheck property-based testing library for automated test case generation and shrinking.
npx @tessl/cli install tessl/maven-org-specs2--specs2-scalacheck@4.21.0A Scala library that provides seamless integration between the specs2 testing framework and ScalaCheck property-based testing. This integration enables developers to write property-based tests using ScalaCheck's automatic test case generation, shrinking capabilities, and statistical analysis within specs2's behavior-driven development (BDD) specification DSL.
libraryDependencies += "org.specs2" %% "specs2-scalacheck" % "4.21.0"import org.specs2.ScalaCheckFor individual components:
import org.specs2.scalacheck._import org.specs2._
import org.specs2.ScalaCheck
import org.scalacheck._
class MySpec extends Specification with ScalaCheck { def is = s2"""
String concatenation properties
concatenation length ${prop((s1: String, s2: String) =>
(s1 + s2).length == s1.length + s2.length)}
empty string identity ${prop((s: String) =>
s + "" == s && "" + s == s)}
Integer arithmetic properties
addition commutativity ${prop((a: Int, b: Int) =>
a + b == b + a)}
multiplication by zero ${prop((n: Int) =>
n * 0 == 0)}
"""
}The specs2-scalacheck integration follows a modular architecture that bridges two testing paradigms:
ScalaCheckPropertyCreation trait provides prop methods that convert functions into testable properties with support for 1-8 parametersScalaCheckPropertyCheck trait handles property execution, result interpretation, and seed management for reproducible testsParameters case class encapsulates all ScalaCheck test parameters plus specs2-specific configurationAsResultProp trait provides seamless conversion between specs2's Result types and ScalaCheck's Prop typesScalaCheckPropertyDsl trait enables properties to be used directly in specs2 specificationsThis architecture allows property-based tests to integrate seamlessly with specs2's specification DSL while preserving ScalaCheck's full feature set including custom generators, shrinkers, and statistical data collection.
Create property-based tests from functions with automatic test case generation and shrinking. Supports functions with 1-8 parameters, custom generators, shrinkers, and data collectors.
def prop[T, R](result: T => R)(implicit
arbitrary: Arbitrary[T],
shrink: Shrink[T],
pretty: T => Pretty,
prettyFreqMap: FreqMap[Set[Any]] => Pretty,
asResult: AsResult[R],
parameters: Parameters
): ScalaCheckFunction1[T, R]
def prop[T1, T2, R](result: (T1, T2) => R)(implicit ...): ScalaCheckFunction2[T1, T2, R]
// ... up to 8 parametersConfigure test execution parameters including number of tests, generator sizes, random seeds, verbosity, and worker threads. Supports both programmatic configuration and command-line parameter overrides.
case class Parameters(
minTestsOk: Int = 100,
minSize: Int = 0,
maxDiscardRatio: Float = 5.0f,
maxSize: Int = 100,
workers: Int = 1,
testCallback: Test.TestCallback = Test.Parameters.default.testCallback,
loader: Option[ClassLoader] = None,
prettyParams: Pretty.Params = Pretty.defaultParams,
seed: Option[Seed] = None
)
def set(minTestsOk: Int = ..., minSize: Int = ..., ...): Parameters
def display(minTestsOk: Int = ..., minSize: Int = ..., ...): ParametersExecute properties with comprehensive result reporting, failure analysis, and statistical data collection. Includes seed capture for reproducible test runs and detailed error reporting.
def check(prop: Prop, parameters: Parameters, prettyFreqMap: FreqMap[Set[Any]] => Pretty): Result
def checkProperties(properties: Properties, parameters: Parameters, prettyFreqMap: FreqMap[Set[Any]] => Pretty): ResultSeamless conversion between specs2 and ScalaCheck types with automatic result interpretation and property wrapping. Supports all specs2 result types and ScalaCheck property types.
implicit def asResultToProp[R : AsResult](r: R): Prop
implicit def propAsResult(implicit p: Parameters, pfq: FreqMap[Set[Any]] => Pretty): AsResult[Prop]
implicit def propertiesAsResult(implicit p: Parameters, pfq: FreqMap[Set[Any]] => Pretty): AsResult[Properties]// Main integration trait
trait ScalaCheck extends
ScalaCheckPropertyCreation with
ScalaCheckPropertyCheck with
ScalaCheckParameters with
AsResultProp with
ScalaCheckPropertyDsl with
GenInstances
// Property wrapper types
trait ScalaCheckProperty {
type SelfType <: ScalaCheckProperty
def prop: Prop
def parameters: Parameters
def prettyFreqMap: FreqMap[Set[Any]] => Pretty
def setParameters(ps: Parameters): SelfType
def setSeed(seed: Seed): SelfType
def setSeed(seed: String): SelfType
}
// Type class instances container
case class ScalaCheckArgInstances[T](
arbitrary: Arbitrary[T],
shrink: Option[Shrink[T]],
collectors: List[T => Any],
pretty: T => Pretty
)
// Functional programming support for generators
trait GenInstances {
implicit def genMonad: Monad[Gen]
}