Scala testing library with actionable errors and extensible APIs
npx @tessl/cli install tessl/maven-org-scalameta--munit_2-13@1.1.0MUnit is a comprehensive Scala testing framework that provides actionable error messages and extensible APIs for writing and running tests. It supports cross-platform development across JVM, JavaScript, and Native platforms, offering a modern alternative to traditional testing frameworks like ScalaTest.
libraryDependencies += "org.scalameta" %% "munit" % "1.1.1" % Testimport munit.FunSuiteFor additional functionality:
import munit._
import munit.Assertions
import munit.Locationimport munit.FunSuite
class ExampleSuite extends FunSuite {
test("basic assertion") {
val result = 2 + 2
assertEquals(result, 4)
}
test("string comparison") {
val message = "Hello, World!"
assert(message.startsWith("Hello"))
}
test("exception handling") {
intercept[ArithmeticException] {
10 / 0
}
}
test("async test") {
Future.successful(42).map { result =>
assertEquals(result, 42)
}
}
}MUnit's architecture is built around several key components:
Suite, FunSuite) that organize and execute testsThe design emphasizes simplicity for basic use cases while providing powerful extension points for advanced scenarios through the transform system and fixture architecture.
Core test suite classes that users extend to write tests. Includes FunSuite for function-style tests and Suite for minimal custom test suites.
abstract class FunSuite extends BaseFunSuite
abstract class Suite extends PlatformSuite {
def munitTests(): Seq[Test]
def munitFixtures: Seq[AnyFixture[_]] = Nil
def beforeAll(): Unit = ()
def afterAll(): Unit = ()
def beforeEach(context: BeforeEach): Unit = ()
def afterEach(context: AfterEach): Unit = ()
}Rich assertion methods with type-safe comparisons and helpful diff output for test failures. Includes basic assertions, equality checks, exception handling, and failure methods.
def assert(cond: => Boolean, clue: => Any = "assertion failed")(implicit loc: Location): Unit
def assertEquals[A, B](obtained: A, expected: B, clue: => Any = "values are not the same")(implicit loc: Location, compare: Compare[A, B]): Unit
def intercept[T <: Throwable](body: => Any)(implicit T: ClassTag[T], loc: Location): T
def fail(message: String, clues: Clues = new Clues(Nil))(implicit loc: Location): NothingTest configuration classes and metadata types for organizing and controlling test execution. Includes test options, tags, and source location tracking.
final class TestOptions(val name: String, val tags: Set[Tag], val location: Location) {
def tag(t: Tag): TestOptions
def ignore: TestOptions
def only: TestOptions
def fail: TestOptions
def flaky: TestOptions
}
class Tag(val value: String) extends AnnotationFlexible fixture system for managing test resources with both synchronous and asynchronous support. Includes base fixtures, function-style fixtures, and lifecycle hooks.
abstract class AnyFixture[T](val fixtureName: String) {
def apply(): T
def beforeAll(): Any = ()
def afterAll(): Any = ()
}
abstract class Fixture[T](name: String) extends AnyFixture[T](name)
abstract class FutureFixture[T](name: String) extends AnyFixture[T](name)Comprehensive exception classes for test failures with IDE integration and detailed error reporting. Includes comparison failures, suite failures, and custom exception types.
class FailException(val message: String, val cause: Throwable, val isStackTracesEnabled: Boolean, val location: Location) extends AssertionError
class ComparisonFailException extends ComparisonFailure with FailExceptionLike[ComparisonFailException]Extensible transform system for customizing test and suite behavior. Allows modification of individual tests, entire suites, and return value handling.
final class TestTransform(val name: String, fn: Test => Test) extends Function1[Test, Test]
final class SuiteTransform(val name: String, fn: List[Test] => List[Test]) extends Function1[List[Test], List[Test]]
final class ValueTransform(val name: String, fn: PartialFunction[Any, Future[Any]]) extends Function1[Any, Option[Future[Any]]]final class Test(val name: String, val body: () => Future[Any], val tags: Set[Tag], val location: Location)
final class Location(val path: String, val line: Int) extends Annotation
class BeforeEach(val test: Test)
class AfterEach(val test: Test)