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

test-suites.mddocs/

Test Suites

Core test suite classes that provide the foundation for writing and organizing tests in MUnit. Users extend these classes to create test suites with different levels of functionality and customization.

Capabilities

FunSuite - Function-Style Test Suite

The primary test suite class that most users should extend. Provides a simple test() method for defining tests with automatic async support.

/**
 * Main test suite class for function-style tests
 */
abstract class FunSuite extends BaseFunSuite

trait BaseFunSuite 
    extends Suite 
    with Assertions 
    with FunFixtures 
    with TestOptionsConversions 
    with TestTransforms 
    with SuiteTransforms 
    with ValueTransforms {
  
  /** Define a test with a name and body */
  def test(name: String)(body: => Any)(implicit loc: Location): Unit
  
  /** Define a test with options and body */
  def test(options: TestOptions)(body: => Any)(implicit loc: Location): Unit
  
  /** Configure test timeout (default: 30 seconds) */
  def munitTimeout: Duration
  
  /** Get all tests in this suite */
  def munitTests(): Seq[Test]
}

Usage Examples:

import munit.FunSuite
import scala.concurrent.Future

class MyTestSuite extends FunSuite {
  test("simple test") {
    assertEquals(2 + 2, 4)
  }
  
  test("test with custom options".tag(Slow)) {
    // This test is marked as slow
    Thread.sleep(1000)
    assert(true)
  }
  
  test("async test") {
    Future.successful(42).map { result =>
      assertEquals(result, 42)
    }
  }
  
  test("test that should fail".fail) {
    // This test is expected to fail
    assertEquals(1, 2)
  }
}

Suite - Base Test Suite

Minimal base class for custom test suites. Use this when you need full control over test execution and don't need the convenience methods provided by FunSuite.

/**
 * Base class for all test suites with minimal functionality
 */
@RunWith(classOf[MUnitRunner])
abstract class Suite extends PlatformSuite {
  
  // Type aliases for convenience
  final type TestValue = Future[Any]
  final type Fixture[T] = munit.Fixture[T]
  final type Test = munit.Test
  final type BeforeEach = munit.BeforeEach
  final type AfterEach = munit.AfterEach
  
  /** Abstract method to return all tests in the suite */
  def munitTests(): Seq[Test]
  
  /** Suite-level fixtures for resource management */
  def munitFixtures: Seq[AnyFixture[_]] = Nil
  
  /** Execution context for async operations */
  def munitExecutionContext: ExecutionContext
  
  /** Runs once before all tests in the suite */
  def beforeAll(): Unit = ()
  
  /** Runs once after all tests in the suite */
  def afterAll(): Unit = ()
  
  /** Runs before each individual test */
  def beforeEach(context: BeforeEach): Unit = ()
  
  /** Runs after each individual test */
  def afterEach(context: AfterEach): Unit = ()
}

Usage Examples:

import munit._
import scala.concurrent.Future

class CustomSuite extends Suite {
  private val tests = List(
    new Test("custom test 1", () => Future.successful(assert(true)), Set.empty, Location.empty),
    new Test("custom test 2", () => Future.successful(assertEquals(1 + 1, 2)), Set.empty, Location.empty)
  )
  
  def munitTests(): Seq[Test] = tests
  
  override def beforeAll(): Unit = {
    println("Setting up test suite")
  }
  
  override def afterAll(): Unit = {
    println("Tearing down test suite")
  }
  
  override def beforeEach(context: BeforeEach): Unit = {
    println(s"Running test: ${context.test.name}")
  }
}

Platform-Specific Components

Platform-specific base traits that provide platform-dependent functionality.

/**
 * Platform-specific base functionality
 * Implementation varies by platform (JVM/JS/Native)
 */
trait PlatformSuite

Platform-Specific Features:

For JavaScript and Native platforms:

/**
 * Annotation to ignore an entire test suite (JS/Native only)
 */
class IgnoreSuite extends Annotation

Suite Configuration

Lifecycle Hooks

All suite classes provide hooks for setup and teardown operations:

  • beforeAll(): Runs once before all tests
  • afterAll(): Runs once after all tests
  • beforeEach(context): Runs before each test
  • afterEach(context): Runs after each test

Execution Context

Suites can customize the execution context for async operations by overriding munitExecutionContext. The default is a parasitic execution context that runs tasks synchronously.

Test Collection

The munitTests() method returns all tests for the suite. In FunSuite, this is handled automatically, but custom suites need to implement this method.