Installation

You'll need to install the following dependencies to test your programs against cats.effect.IO

SBT (1.9.0+)

Newer versions of SBT have weaver automatically integrated.

libraryDependencies +=  "com.disneystreaming" %% "weaver-cats" % "0.0-0e0ca96-SNAPSHOT" % Test

SBT (older versions)

Internally, SBT has a hardcoded list of test frameworks it integrates with. weaver must be manually added to this list.

libraryDependencies +=  "com.disneystreaming" %% "weaver-cats" % "0.0-0e0ca96-SNAPSHOT" % Test
testFrameworks += new TestFramework("weaver.framework.CatsEffect")

Mill

object test extends Tests {
  def ivyDeps = Agg(
    ivy"com.disneystreaming::weaver-cats:0.0-0e0ca96-SNAPSHOT"
  )
  def testFramework = "weaver.framework.CatsEffect"
}

scala-cli

//> using lib "com.disneystreaming::weaver-cats:0.0-0e0ca96-SNAPSHOT"
//> using testFramework "weaver.framework.CatsEffect" // this may neccessary if you have other TestFramework on your dependencies

Usage

Start with importing the following :

import weaver._

The most basic usage is to extend SimpleIOSuite. Tests are registered imperatively, very much like in scalatest's FunSuite or in utest, but their bodies are "weaved" together in a single IO that the framework executes when the build tool asks for it.

import cats.effect._

// Suites must be "objects" for them to be picked by the framework
object MySuite extends SimpleIOSuite {

  val randomUUID = IO(java.util.UUID.randomUUID())

  // A test for side-effecting functions
  test("hello side-effects") {
    for {
      x <- randomUUID
      y <- randomUUID
    } yield expect(x != y)
  }

}