Testing utilities and helpers for the Cats functional programming library with controlled type class instances for property-based testing
npx @tessl/cli install tessl/maven-org-typelevel--cats-testkit@2.13.0Cats 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.
build.sbt: "org.typelevel" %% "cats-testkit" % "2.13.0" % Testimport cats.tests._
import cats.tests.Helpers._For ScalaCheck integration:
import org.scalacheck.{Arbitrary, Cogen}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])
}
}Cats Testkit provides two main testing utilities:
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.
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 NProvides 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
}