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 1ms
- pure failing test 0ms
- failing test with logs 3ms

*************FAILURES*************
MySuite
- failing test with side-effects 1ms
  Values not equal:

  in expect.eql(
- expected, + found)
  -a4931642-bb07-4e16-bef2-0f2ecedc0ba7
  +57c3681d-6bfd-4752-a904-aa9af3622274

  installation.md#L25
      } yield expect.eql(x, y)
                        ^
- pure failing test 0ms
  Values not equal:

  in expect.eql(
- expected, + found)
  -5
  +6

  installation.md#L29
      expect.eql("hello".size, 6)
                ^
- failing test with logs 3ms
  Values not equal:

  in expect.eql(
- expected, + found)
  -0bb556b6-c1c3-4af3-adf0-bdf11d37c9be
  +37498158-06cd-498a-8198-40542b9cc47a

  installation.md#L38
      } yield expect.eql(x, y)
                        ^


    [INFO] 11:43:16 [installation.md:35] x : 0bb556b6-c1c3-4af3-adf0-bdf11d37c9be
    [INFO] 11:43:16 [installation.md:37] y : 37498158-06cd-498a-8198-40542b9cc47a 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