or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

dsl-integration.mdindex.mdproperty-checking.mdproperty-configuration.mdproperty-creation.mdresult-conversion.mdutilities.md
tile.json

tessl/maven-org-specs2--specs2-scalacheck-2-12

ScalaCheck integration for specs2 testing framework - provides property-based testing capabilities with seamless integration into specs2 specifications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.specs2/specs2-scalacheck_2.12@3.10.x

To install, run

npx @tessl/cli install tessl/maven-org-specs2--specs2-scalacheck-2-12@3.10.0

index.mddocs/

specs2-scalacheck

specs2-scalacheck provides ScalaCheck integration for the specs2 testing framework, enabling property-based testing within specs2 specifications. It bridges ScalaCheck's powerful property generators and testing capabilities with specs2's expressive DSL and comprehensive reporting system.

Package Information

  • Package Name: specs2-scalacheck_2.12
  • Package Type: maven
  • Language: Scala
  • Installation: Add to your build.sbt:
    libraryDependencies += "org.specs2" %% "specs2-scalacheck" % "3.10.0"

Core Imports

import org.specs2.ScalaCheck
import org.specs2.scalacheck._

For specific functionality:

import org.specs2.scalacheck.{Parameters, ScalaCheckProperty}

Basic Usage

import org.specs2.{Specification, ScalaCheck}
import org.scalacheck.{Arbitrary, Gen}

class MySpec extends Specification with ScalaCheck { def is = s2"""
  Basic property testing
    addition is commutative $commutativeAddition
    string reversal twice returns original $doubleReverse
"""

  def commutativeAddition = prop { (a: Int, b: Int) =>
    a + b must_== b + a
  }

  def doubleReverse = prop { (s: String) =>
    s.reverse.reverse must_== s
  }
}

Architecture

specs2-scalacheck is built around several key components:

  • Property Creation: Methods to create ScalaCheck properties from functions with 1-8 parameters
  • Parameter Configuration: Comprehensive system for configuring test parameters with command line overrides
  • Property Checking: Core execution engine that runs properties and formats results
  • Result Conversion: Bidirectional conversion between ScalaCheck and specs2 result types
  • DSL Integration: Seamless integration with specs2's specification DSL
  • Context Support: Setup/teardown actions around property execution

Capabilities

Property Creation

Core functionality for creating ScalaCheck properties from test functions. Supports functions with 1-8 parameters with full typeclass customization.

trait ScalaCheckPropertyCreation {
  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]
}

Property Creation

Property Configuration

Comprehensive parameter configuration system with fluent API for setting test parameters, verbosity, and ScalaCheck settings.

case class Parameters(
  minTestsOk: Int = Test.Parameters.default.minSuccessfulTests,
  minSize: Int = Test.Parameters.default.minSize,
  maxDiscardRatio: Float = Test.Parameters.default.maxDiscardRatio,
  maxSize: Int = Test.Parameters.default.maxSize,
  workers: Int = Test.Parameters.default.workers,
  testCallback: Test.TestCallback = Test.Parameters.default.testCallback,
  loader: Option[ClassLoader] = Test.Parameters.default.customClassLoader,
  prettyParams: Pretty.Params = Pretty.defaultParams
)

Property Configuration

Property Execution and Checking

Core property checking functionality that executes ScalaCheck properties and converts results to specs2 format.

trait ScalaCheckPropertyCheck {
  def check(
    prop: Prop, 
    parameters: Parameters, 
    prettyFreqMap: FreqMap[Set[Any]] => Pretty
  ): Result
  
  def checkProperties(
    properties: Properties, 
    parameters: Parameters, 
    prettyFreqMap: FreqMap[Set[Any]] => Pretty
  ): Result
}

Property Checking

Result Conversion

Bidirectional conversion system between ScalaCheck Prop/Properties and specs2 AsResult types for seamless integration.

trait AsResultProp {
  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]
}

Result Conversion

DSL Integration

Integration with specs2's specification DSL for displaying Properties as examples and converting Prop objects.

trait ScalaCheckPropertyDsl {
  implicit def propToScalaCheckProperty(prop: Prop)(implicit 
    parameters: Parameters, 
    prettyFreqMap: FreqMap[Set[Any]] => Pretty
  ): ScalaCheckProp
  
  def properties(ps: Properties): Fragments
}

DSL Integration

Utilities

Utility traits and objects for expectation control, pretty printing enhancements, and Scalaz integration.

trait OneExpectationPerProp extends AsResultProp
object PrettyProduct
object PrettyDetails  
trait GenInstances

Utilities

Types

// Main entry point trait combining all functionality
trait ScalaCheck extends 
  ScalaCheckPropertyCreation with
  ScalaCheckPropertyCheck with
  ScalaCheckParameters with
  AsResultProp with
  ScalaCheckPropertyDsl with
  GenInstances

// Base property trait
trait ScalaCheckProperty {
  type SelfType <: ScalaCheckProperty
  def prop: Prop
  def parameters: Parameters
  def prettyFreqMap: FreqMap[Set[Any]] => Pretty
  def setParameters(ps: Parameters): SelfType
  def setVerbosity(v: Int): SelfType
  def verbose: SelfType
}

// Property with context support
trait ScalaCheckFunction extends ScalaCheckProperty {
  def noShrink: SelfType
  def context: Option[Context]
  def setContext(context: Context): SelfType
  def before(action: =>Any): SelfType
  def after(action: =>Any): SelfType
  def around(action: Result => Result): SelfType
}

// Simple property wrapper
case class ScalaCheckProp(
  prop: Prop, 
  parameters: Parameters, 
  prettyFreqMap: FreqMap[Set[Any]] => Pretty
) extends ScalaCheckProperty

// Parameter bundle for typeclass instances
case class ScalaCheckArgInstances[T](
  arbitrary: Arbitrary[T], 
  shrink: Option[Shrink[T]], 
  collectors: List[T => Any], 
  pretty: T => Pretty
)

// Utility trait for controlling expectation counts in specs2
trait OneExpectationPerProp extends AsResultProp {
  implicit override def propAsResult(implicit p: Parameters, pfq: FreqMap[Set[Any]] => Pretty): AsResult[Prop]
  implicit override def propertiesAsResult(implicit p: Parameters, pfq: FreqMap[Set[Any]] => Pretty): AsResult[Properties]
}

// Utility object for creating Pretty instances for case classes
object PrettyProduct {
  def toString[P <: Product](p: P): String
  def apply[P <: Product]: P => Pretty
}

// Utility object for handling failure details in frequency maps
object PrettyDetails {
  def collectDetails[T](fq: FreqMap[Set[T]]): execute.Details
  def removeDetails(fq: FreqMap[Set[Any]]): FreqMap[Set[Any]]
}

// Utility trait for controlling expectation counts in specs2
trait OneExpectationPerProp extends AsResultProp {
  implicit override def propAsResult(implicit p: Parameters, pfq: FreqMap[Set[Any]] => Pretty): AsResult[Prop]
  implicit override def propertiesAsResult(implicit p: Parameters, pfq: FreqMap[Set[Any]] => Pretty): AsResult[Properties]
}

// Scalaz typeclass instances for ScalaCheck Gen
trait GenInstances {
  implicit def genMonad: Monad[Gen]
}