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.
Weaver-test is currently published for Scala 2.12, 2.13, and 3
SBT (1.9.0+)
Newer versions of SBT have weaver automatically integrated.
libraryDependencies += "org.typelevel" %% "weaver-cats" % "0.10.1" % 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.10.1" % Test
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
Mill
object test extends Tests {
def ivyDeps = Agg(
ivy"org.typelevel::weaver-cats:0.10.1"
)
def testFramework = "weaver.framework.CatsEffect"
}
scala-cli
//> using lib "org.typelevel::weaver-cats:0.10.1"
//> using testFramework "weaver.framework.CatsEffect" // this may be neccessary if you have other testFramework on your dependencies
Gradle
With Gradle plugin for multi-backend Scala:
plugins {
id 'org.podval.tools.scalajs' version '<latest version>'
}
dependencies {
testImplementation scalaBackend.testFramework(org.podval.tools.test.framework.WeaverTest)
}
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)
}
}