Cats-effect usage
Installation
You'll need to install the following depending to test your programs against cats.effect.IO
SBT
libraryDependencies += "com.disneystreaming" %% "weaver-cats" % "0.6.0-M4" % Test
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
Mill
object test extends Tests {
def ivyDeps = Agg(
ivy"com.disneystreaming::weaver-cats:0.6.0-M4"
)
def testFrameworks = Seq("weaver.framework.CatsEffect")
}
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
simpleTest("hello side-effects") {
for {
x <- randomUUID
y <- randomUUID
} yield expect(x != y)
}
}