Skip to main content
Version: 2.x

MUnit ZIO

MUnit ZIO is an integration library between MUnit and ZIO.

Introductionโ€‹

MUnit is a Scala testing library that is implemented as a JUnit runner. It has actionable errors, so the test reports are colorfully pretty-printed, stack traces are highlighted, error messages are pointed to the source code location where the failure happened.

The MUnit ZIO enables us to write tests that return ZIO values without needing to call any unsafe methods (e.g. Runtime#unsafeRun).

Installationโ€‹

In order to use this library, we need to add the following lines in our build.sbt file:

libraryDependencies += "org.scalameta" %% "munit" % "0.7.27" % Test
libraryDependencies += "com.github.poslegm" %% "munit-zio" % "0.0.2" % Test

If we are using a version of sbt lower than 1.5.0, we will also need to add:

testFrameworks += new TestFramework("munit.Framework")

Exampleโ€‹

Here is a simple MUnit spec that is integrated with the ZIO effect:

import munit._
import zio._

class SimpleZIOSpec extends ZSuite {
testZ("1 + 1 = 2") {
for {
a <- ZIO(1)
b <- ZIO(1)
}
yield assertEquals(a + b, 2)
}
}

ZIO Chat

๐Ÿ”ฅ Ignite your ZIO journey with ZIO Chat! ๐Ÿ”ฅ Ready to unravel the intricacies of ZIO? As your trusty sidekick, I'm here to light the way. No matter if you're wandering through functional forests or traversing effectful landscapes, I've got answers to keep you on track. Your ZIO adventure starts here โ€“ ask me anything and let's explore together!