Skip to main content

Integration with MUnit

MUnit

Scala Hedgehog provides an integration module for munit. This allows you to define property-based and example-based Hedgehog tests within a munit test suite. If you use this integration, you won't need to Scala Hedgehog sbt testing extension, because you're using the one provided by munit:

val hedgehogVersion = "0.10.1"
libraryDependencies += "qa.hedgehog" %% "hedgehog-munit" % hedgehogVersion % Test
NOTE

If you're using sbt version 1.9.0 or lower, you need to add the following line to your build.sbt file:

testFrameworks += TestFramework("hedgehog.sbt.Framework")
NOTE

For sbt version 1.9.1 or higher, this step is not necessary, as Hedgehog is supported by default.

Here's an example of using hedgehog-munit:

import hedgehog.munit.HedgehogSuite
import hedgehog._

class ReverseSuite extends HedgehogSuite {
property("reverse alphabetic strings") {
for {
xs <- Gen.alpha.list(Range.linear(0, 100)).forAll
} yield assertEquals(xs.reverse.reverse, xs)
}

test("reverse hello") {
withMunitAssertions{ assertions =>
assertions.assertEquals("hello".reverse, "olleh")
}
"hello".reverse ==== "olleh"
}
}

HedgehogSuite provides munit-like assertions, along with all the hedgehog.Result methods and members, that return results in the standard hedgehog report format while satisfying munit's exception-based test failures.