Installation
The stewardship of Weaver has moved from disneystreaming
to typelevel
.
You can migrate from previous versions of weaver by following the migration guide, or learn more about the stewardship.
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 += "org.typelevel" %% "weaver-cats" % "0.9.0" % 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 += "org.typelevel" %% "weaver-cats" % "0.9.0" % Test
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
Mill
object test extends Tests {
def ivyDeps = Agg(
ivy"org.typelevel::weaver-cats:0.9.0"
)
def testFramework = "weaver.framework.CatsEffect"
}
scala-cli
//> using lib "org.typelevel::weaver-cats:0.9.0"
//> 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)
}
}