or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

assertions.mdconfiguration.mdexceptions.mdfixtures.mdindex.mdtest-suites.mdtransforms.md
tile.json

tessl/maven-org-scalameta--munit_2-13

Scala testing library with actionable errors and extensible APIs

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.scalameta/munit_2.13@1.1.x

To install, run

npx @tessl/cli install tessl/maven-org-scalameta--munit_2-13@1.1.0

index.mddocs/

MUnit

MUnit 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.

Package Information

  • Package Name: org.scalameta:munit_2.13
  • Package Type: maven
  • Language: Scala
  • Installation: libraryDependencies += "org.scalameta" %% "munit" % "1.1.1" % Test

Core Imports

import munit.FunSuite

For additional functionality:

import munit._
import munit.Assertions
import munit.Location

Basic Usage

import 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)
    }
  }
}

Architecture

MUnit's architecture is built around several key components:

  • Test Suites: Base classes (Suite, FunSuite) that organize and execute tests
  • Assertions: Type-safe comparison methods with detailed failure messages
  • Fixtures: Resource management for test setup and teardown (synchronous and asynchronous)
  • Transforms: Extensible pipeline for customizing test and suite behavior
  • Framework Integration: JUnit runner for IDE support and SBT framework for build tools
  • Cross-Platform Support: Unified API across JVM, JavaScript, and Native platforms

The design emphasizes simplicity for basic use cases while providing powerful extension points for advanced scenarios through the transform system and fixture architecture.

Capabilities

Test Suite Classes

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 = ()
}

Test Suites

Assertions and Testing

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): Nothing

Assertions

Test Configuration and Metadata

Test 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 Annotation

Configuration

Fixtures and Lifecycle Management

Flexible 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)

Fixtures

Exception Handling

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]

Exceptions

Transforms and Extensions

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]]]

Transforms

Types

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)