All Projects → typelevel → cats-effect-testing

typelevel / cats-effect-testing

Licence: Apache-2.0 license
Integration between cats-effect and test frameworks

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to cats-effect-testing

pfps-examples
🏮 Standalone examples shown in the book "Practical FP in Scala: A hands-on approach"
Stars: ✭ 167 (+7.74%)
Mutual labels:  cats, cats-effect
fs2-ssh
A wrapper around Apache SSHD targeting cats-effect and fs2
Stars: ✭ 36 (-76.77%)
Mutual labels:  cats, cats-effect
tagless-final-jam
Workshop On Tagless Final Interpreters
Stars: ✭ 37 (-76.13%)
Mutual labels:  cats, cats-effect
tutorials
🎥 Source code of the examples shown in the video tutorials
Stars: ✭ 18 (-88.39%)
Mutual labels:  cats, cats-effect
fs2-ftp
Simple client for Ftp/Ftps/Sftp
Stars: ✭ 24 (-84.52%)
Mutual labels:  cats, cats-effect
tinyweb
Simple and lightweight HTTP async server for micropython
Stars: ✭ 182 (+17.42%)
Mutual labels:  cats, cats-effect
skafka
Scala wrapper for kafka consumer and producer
Stars: ✭ 35 (-77.42%)
Mutual labels:  cats, cats-effect
scala-functional-programming-tutorial
Functional Programming in Scala Tutorial
Stars: ✭ 23 (-85.16%)
Mutual labels:  cats, cats-effect
console4cats
💻 Effect-type agnostic Console I/O for Cats Effect (archived, use Cats Effect 3 instead)
Stars: ✭ 55 (-64.52%)
Mutual labels:  cats, cats-effect
telegramium
Telegramium or F[ Tg ] - pure functional Telegram Bot API implementation for Scala.
Stars: ✭ 42 (-72.9%)
Mutual labels:  cats, cats-effect
classy-optics
🔎 Source code shown at my talks at Scale by the Bay 2018 and Scalar 2019
Stars: ✭ 25 (-83.87%)
Mutual labels:  cats, cats-effect
cats-helper
Helpers for cats & cats-effect
Stars: ✭ 19 (-87.74%)
Mutual labels:  cats, cats-effect
typelevel-stack.g8
📚 Unofficial Giter8 template for the Typelevel Stack (Http4s / Doobie / Circe / Cats Effect / Fs2) based on Cats v1.x.x
Stars: ✭ 63 (-59.35%)
Mutual labels:  cats, cats-effect
Monix
Asynchronous, Reactive Programming for Scala and Scala.js.
Stars: ✭ 1,819 (+1073.55%)
Mutual labels:  cats, cats-effect
influencer-stats
Playground for measuring performance of functional programming tools in Scala. Gathers statistics about videos.
Stars: ✭ 24 (-84.52%)
Mutual labels:  cats, cats-effect
tradeio
A disciplined way to purely functional domain models in Scala
Stars: ✭ 19 (-87.74%)
Mutual labels:  cats, cats-effect
vault4s
Vault Client Library For Scala
Stars: ✭ 15 (-90.32%)
Mutual labels:  cats, cats-effect
swam
WebAssembly engine in Scala
Stars: ✭ 38 (-75.48%)
Mutual labels:  cats, cats-effect
Filterous 2
Instagram-like photo manipulation library for Node.js and Javascript on browser
Stars: ✭ 163 (+5.16%)
Mutual labels:  cats
Scala Exercises
The easy way to learn Scala.
Stars: ✭ 2,431 (+1468.39%)
Mutual labels:  cats

cats-effect-testing

A quickie little utility which makes it easier to write tests using specs2 (mutable or functional), scalatest, µTest or minitest where the examples are effectful within cats.effect.IO.

Specs2

import cats.effect.IO
import cats.effect.testing.specs2.CatsEffect
import org.specs2.mutable.Specification

// for some reason, only class works here; object will not be detected by sbt
class ExampleSpec extends Specification with CatsEffect {
  "examples" should {
    "do the things" in IO {
      true must beTrue
    }
  }
}

The above compiles and runs exactly as you would expect.

By default, tests run with a 10 second timeout. If you wish to override this, simply override the inherited Timeout val:

override val Timeout = 5.seconds

If you need an ExecutionContext, one is available in the executionContext val.

And if you need to share Cats Effect's Resource between test examples you can extend CatsResource, like so:

import cats.effect.{IO, Ref, Resource}
import org.specs2.mutable.SpecificationLike

class CatsResourceSpecs extends CatsResource[IO, Ref[IO, Int]] with SpecificationLike {
  sequential

  val resource: Resource[IO, Ref[IO, Int]] =
    Resource.make(Ref[IO].of(0))(_.set(Int.MinValue))

  "cats resource support" should {
    "run a resource modification" in withResource { ref =>
      ref.modify{ a =>
        (a + 1, a)
      }.map(
        _ must_=== 0
      )
    }

    "be shared between tests" in withResource { ref =>
      ref.modify{ a =>
        (a + 1, a)
      }.map(
        _ must_=== 1
      )
    }
  }
}

The Resource is acquired before the tests are run and released afterwards. A more realistic example would be to share a Resource that takes a long time to start up.

Usage

libraryDependencies += "org.typelevel" %% "cats-effect-testing-specs2" % "<version>" % Test

Published for Scala 3.1+, 2.13, 2.12, as well as ScalaJS 1.7+. Depends on Cats Effect 3.1+ and Specs2 4.13.x. Specs2 5.0 is not yet supported.

Early versions (0.x.y) were published under the com.codecommit groupId.

ScalaTest

import cats.effect._
import cats.effect.testing.scalatest.AsyncIOSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.freespec.AsyncFreeSpec

class MySpec extends AsyncFreeSpec with AsyncIOSpec with Matchers {

  "My Code " - {
    "works" in {
      IO(1).asserting(_ shouldBe 1)
    }
}

Usage

libraryDependencies += "org.typelevel" %% "cats-effect-testing-scalatest" % "<version>" % Test

Published for Scala 3.1+, 2.13, 2.12, as well as ScalaJS 1.7.x. Depends on Cats Effect 3.1+ and scalatest 3.2.6.

Early versions (0.x.y) were published under the com.codecommit groupId.

µTest

import scala.concurrent.duration._
import utest._
import cats.implicits._
import cats.effect.IO
import cats.effect.testing.utest.IOTestSuite

object SimpleSuite extends IOTestSuite {
  override val timeout = 1.second // Default timeout is 10 seconds

  val tests = Tests {
    test("do the thing") {
      IO(assert(true))
    }
  }
}

Usage

libraryDependencies += "org.typelevel" %% "cats-effect-testing-utest" % "<version>" % Test

Published for Scala 3.1+, 2.13, 2.12, as well as ScalaJS 1.7.x. Depends on Cats Effect 3.1+ and µTest 0.7.9.

Early versions (0.x.y) were published under the com.codecommit groupId.

Minitest

Minitest is very similar to uTest, but being strongly typed, there's no need to support non-IO tests

import scala.concurrent.duration._
import cats.implicits._
import cats.effect.IO
import cats.effect.testing.minitest.IOTestSuite

object SimpleSuite extends IOTestSuite {
  override val timeout = 1.second // Default timeout is 10 seconds

  test("do the thing") {
    IO(assert(true))
  }
}

Usage

libraryDependencies += "org.typelevel" %% "cats-effect-testing-minitest" % "<version>" % Test

Published for Scala 3.1+, 2.13, 2.12, as well as ScalaJS 1.7.x. Depends on Cats Effect 3.1+ and minitest 2.9.5.

Early versions (0.x.y) were published under the com.codecommit groupId.

Similar projects

scalacheck-effect

scalacheck-effect is a library that extends the functionality of ScalaCheck to support "effectful" properties. An effectful property is one that evaluates each sample in some type constructor F[_].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].