Logging information
Weaver provides each individual test with a lazy-logger. The log statements only get reported if the test is unsuccessful. Because tests in weaver run in parallel by default, this makes it easier to tie printed information to the test it originated from.
import weaver._
import cats.effect._
object LoggedTests extends IOSuite {
// Only the logger is received as an argument
loggedTest("Just logging some stuff") { log =>
for {
_ <- log.info("oopsie daisy")
} yield expect(2 + 2 == 5)
}
// We can obviously have tests receive loggers AND shared resources
override type Res = String
override def sharedResource : Resource[IO, Res] =
Resource.pure[IO, Res]("hello")
// Both the logger and the resource are received as arguments
test("Good requests lead to good results") { (sharedString, log) =>
for {
_ <- log.info(sharedString)
} yield expect(2 + 2 == 4)
}
}
LoggedTests
+ Good requests lead to good results 9ms
- Just logging some stuff 8ms
*************FAILURES*************
LoggedTests
- Just logging some stuff 8ms
assertion failed (logging.md:20)
} yield expect(2 + 2 == 5)
[INFO] 17:50:43 [logging.md:19] oopsie daisy
Total 2, Failed 1, Passed 1, Ignored 0, Cancelled 0