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 2ms - pure failing test 2ms - failing test with logs 10ms *************FAILURES************* MySuite - failing test with side-effects 2ms
Values not equal:
in expect.eql(- expected, + found)
-bb3275d5-69f5-4623-b241-e13c4a9dada1
+2fa5ebf2-ff93-4946-a0cb-70bd9bede8fb
installation.md#L25
} yield expect.eql(x, y)
^ - pure failing test 2ms
Values not equal:
in expect.eql(- expected, + found)
-5
+6
installation.md#L29
expect.eql("hello".size, 6)
^ - failing test with logs 10ms
Values not equal:
in expect.eql(- expected, + found)
-b5966f89-2b59-4120-a2fb-05fd52f450bc
+fa25bf51-acda-4766-a44a-a98aadfbdae9
installation.md#L38
} yield expect.eql(x, y)
^
[INFO] 12:32:11 [installation.md:35] x : b5966f89-2b59-4120-a2fb-05fd52f450bc
[INFO] 12:32:11 [installation.md:37] y : fa25bf51-acda-4766-a44a-a98aadfbdae9 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 |