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.13.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.13.0" % Test
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
Mill
object test extends Tests {
def ivyDeps = Agg(
ivy"org.typelevel::weaver-cats:0.13.0"
)
def testFramework = "weaver.framework.CatsEffect"
}
scala-cli
//> using lib "org.typelevel::weaver-cats:0.13.0"
//> 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)
}
Getting started
Start with importing the following :
import weaver._
The most basic usage is to extend SimpleIOSuite.
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())
test("failing test with side-effects") {
for {
x <- randomUUID
y <- randomUUID
} yield expect.eql(x, y)
}
pureTest("pure failing test"){
expect.eql("hello".size, 6)
}
loggedTest("failing test with logs"){ log =>
for {
x <- randomUUID
_ <- log.info(s"x : $x")
y <- randomUUID
_ <- log.info(s"y : $y")
} yield expect.eql(x, y)
}
}
Run your tests with your build tool, e.g. sbt test.
MySuite - failing test with side-effects 7ms - pure failing test 5ms - failing test with logs 8ms *************FAILURES************* MySuite - failing test with side-effects 7ms
Values not equal:
in expect.eql(- expected, + found)
-39bb7a3d-f2d0-4c85-aa99-9d01292aa0f3
+9b8f47fc-1012-4b17-b367-4417b5a1d976
installation.md#L25
} yield expect.eql(x, y)
^ - pure failing test 5ms
Values not equal:
in expect.eql(- expected, + found)
-5
+6
installation.md#L29
expect.eql("hello".size, 6)
^ - failing test with logs 8ms
Values not equal:
in expect.eql(- expected, + found)
-2f2cfa67-ce6a-4499-9b19-b854791a422a
+18005675-4089-4dcf-abef-ceb6053c5a9a
installation.md#L38
} yield expect.eql(x, y)
^
[INFO] 10:24:06 [installation.md:35] x : 2f2cfa67-ce6a-4499-9b19-b854791a422a
[INFO] 10:24:06 [installation.md:37] y : 18005675-4089-4dcf-abef-ceb6053c5a9a Total 3, Failed 3, Passed 0, Ignored 0
Other suites
Weaver also includes support for
| Suite | Use case |
|---|---|
| SimpleIOSuite | Each test is a standalone IO action |
| IOSuite | Each test needs access to a shared Resource |
| FunSuite | Each test is a pure function |