or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

helper-types.mdindex.mdlist-wrapper.md
tile.json

tessl/maven-org-typelevel--cats-testkit

Testing utilities and helpers for the Cats functional programming library with controlled type class instances for property-based testing

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.typelevel/cats-testkit_2.13@2.13.x

To install, run

npx @tessl/cli install tessl/maven-org-typelevel--cats-testkit@2.13.0

index.mddocs/

Cats Testkit

Cats Testkit provides testing utilities and helpers for the Cats functional programming library. It includes concrete types with controlled type class instances and wrapper types that enable comprehensive property-based testing of functional programming abstractions.

Package Information

  • Package Name: cats-testkit
  • Package Type: maven
  • Language: Scala
  • Installation: Add to your build.sbt: "org.typelevel" %% "cats-testkit" % "2.13.0" % Test

Core Imports

import cats.tests._
import cats.tests.Helpers._

For ScalaCheck integration:

import org.scalacheck.{Arbitrary, Cogen}

Basic Usage

import cats.tests._
import cats.tests.Helpers._
import cats.kernel.laws.discipline.MonoidTests
import cats.laws.discipline.AlternativeTests
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.scalacheck.Checkers

class MyMonoidTests extends AnyFunSuite with Checkers {
  // Test that your Monoid[MyType] implementation is lawful
  // using the Mono helper type which has a Monoid instance
  test("Monoid laws for Mono") {
    checkAll("Monoid[Mono]", MonoidTests[Mono].monoid)
  }
  
  // Test different type class instances with ListWrapper
  test("Alternative laws for ListWrapper") {
    implicit val alt = ListWrapper.alternative
    checkAll("ListWrapper Alternative", AlternativeTests[ListWrapper].alternative[Int, Int, Int])
  }
}

Architecture

Cats Testkit provides two main testing utilities:

  1. Helper Types - Concrete data types with precisely controlled type class instances for testing algebraic laws
  2. Wrapper Types - Generic wrapper types that enable testing different combinations of type class constraints

These components work together to enable comprehensive property-based testing of functional programming abstractions, ensuring that type class implementations are lawful across various contexts and constraint combinations.

Capabilities

Helper Types for Type Class Testing

Provides concrete types with controlled type class instances for testing algebraic structures like Semigroup, Monoid, Group, Order, etc.

// Example helper types with specific type class instances
case class Mono(n: Int) extends N
case class Grp(n: Int) extends N  
case class Ord(n: Int) extends N

Helper Types

ListWrapper for Constraint Testing

Provides a wrapper type that enables testing type class instances with different constraint combinations.

final case class ListWrapper[A](list: List[A]) extends AnyVal

object ListWrapper {
  val traverse: Traverse[ListWrapper]
  val monad: Monad[ListWrapper]
  val alternative: Alternative[ListWrapper]
  // ... many more type class instances
}

ListWrapper Testing Infrastructure