CtrlK
BlogDocsLog inGet started
Tessl Logo

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

specs2-scalacheck provides integration between the specs2 testing framework and ScalaCheck property-based testing library for automated test case generation and shrinking.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

specs2-scalacheck

A 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.

Package Information

  • Package Name: specs2-scalacheck
  • Language: Scala
  • Package Type: Maven/SBT
  • Installation: libraryDependencies += "org.specs2" %% "specs2-scalacheck" % "4.21.0"

Core Imports

import org.specs2.ScalaCheck

For individual components:

import org.specs2.scalacheck._

Basic Usage

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)}
"""
}

Architecture

The specs2-scalacheck integration follows a modular architecture that bridges two testing paradigms:

  • Property Creation: The ScalaCheckPropertyCreation trait provides prop methods that convert functions into testable properties with support for 1-8 parameters
  • Property Execution: The ScalaCheckPropertyCheck trait handles property execution, result interpretation, and seed management for reproducible tests
  • Parameter Management: The Parameters case class encapsulates all ScalaCheck test parameters plus specs2-specific configuration
  • Type Integration: The AsResultProp trait provides seamless conversion between specs2's Result types and ScalaCheck's Prop types
  • DSL Integration: The ScalaCheckPropertyDsl trait enables properties to be used directly in specs2 specifications

This 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.

Capabilities

Property Creation

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 parameters

Property Creation

Property Configuration

Configure 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 = ..., ...): Parameters

Configuration

Property Execution

Execute 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): Result

Execution

Type Integration

Seamless 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]

Type Integration

Types

// 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]
}

docs

configuration.md

execution.md

index.md

property-creation.md

type-integration.md

tile.json