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

assertions.mddocs/

Assertions

Rich assertion methods that provide type-safe comparisons with detailed failure messages and helpful diff output. The assertion system is designed to give actionable error messages that help developers quickly identify and fix test failures.

Capabilities

Basic Assertions

Core assertion methods for general-purpose testing.

/**
 * Basic boolean assertion with optional clue
 * @param cond The condition to assert
 * @param clue Additional context for failure messages
 */
def assert(cond: => Boolean, clue: => Any = "assertion failed")(implicit loc: Location): Unit

/**
 * Assumption for conditional test execution
 * @param cond The condition to assume
 * @param clue Additional context if assumption fails
 */
def assume(cond: Boolean, clue: => Any = "assumption failed")(implicit loc: Location): Unit

Usage Examples:

class AssertionExamples extends FunSuite {
  test("basic assertions") {
    assert(2 + 2 == 4)
    assert(List(1, 2, 3).nonEmpty, "List should not be empty")
    
    // Conditional test execution
    assume(System.getProperty("os.name").contains("Linux"))
    // Test only runs on Linux
  }
}

Equality Assertions

Type-safe equality checks with comprehensive diff output for failures.

/**
 * Assert that two values are equal with type-safe comparison
 * @param obtained The actual value
 * @param expected The expected value
 * @param clue Additional context for failure messages
 */
def assertEquals[A, B](obtained: A, expected: B, clue: => Any = "values are not the same")(implicit loc: Location, compare: Compare[A, B], diffOptions: DiffOptions): Unit

/**
 * Assert that two values are not equal
 * @param obtained The actual value
 * @param expected The value that should not match
 * @param clue Additional context for failure messages
 */
def assertNotEquals[A, B](obtained: A, expected: B, clue: => Any = "values are the same")(implicit loc: Location, compare: Compare[A, B]): Unit

Usage Examples:

class EqualityExamples extends FunSuite {
  test("value equality") {
    val user = User("Alice", 25)
    val expected = User("Alice", 25)
    assertEquals(user, expected)
  }
  
  test("collection equality") {
    val list1 = List(1, 2, 3)
    val list2 = List(1, 2, 3)
    assertEquals(list1, list2)
    
    val different = List(1, 2, 4)
    assertNotEquals(list1, different)
  }
  
  test("with custom clue") {
    val result = processData(input)
    assertEquals(result.status, "success", s"Processing failed for input: $input")
  }
}

Numeric Assertions

Specialized assertions for floating-point number comparisons with tolerance.

/**
 * Assert double equality with tolerance for floating-point precision
 * @param obtained The actual double value
 * @param expected The expected double value
 * @param delta The acceptable difference between values
 */
def assertEqualsDouble(obtained: Double, expected: Double, delta: Double, clue: => Any = "values are not the same")(implicit loc: Location): Unit

/**
 * Assert float equality with tolerance for floating-point precision
 * @param obtained The actual float value
 * @param expected The expected float value
 * @param delta The acceptable difference between values
 */
def assertEqualsFloat(obtained: Float, expected: Float, delta: Float, clue: => Any = "values are not the same")(implicit loc: Location): Unit

Usage Examples:

class NumericExamples extends FunSuite {
  test("floating point comparisons") {
    val result = 0.1 + 0.2
    assertEqualsDouble(result, 0.3, 0.0001)
    
    val calculation: Float = 1.0f / 3.0f * 3.0f
    assertEqualsFloat(calculation, 1.0f, 0.0001f)
  }
}

String Assertions

String comparison with diff visualization for easy identification of differences.

/**
 * Assert string equality with diff output for mismatches
 * @param obtained The actual string
 * @param expected The expected string
 * @param clue Additional context for failure messages
 */
def assertNoDiff(obtained: String, expected: String, clue: => Any = "diff assertion failed")(implicit loc: Location, diffOptions: DiffOptions): Unit

Usage Examples:

class StringExamples extends FunSuite {
  test("string comparison with diff") {
    val generated = generateHtml()
    val expected = """
      |<html>
      |  <body>
      |    <h1>Hello, World!</h1>
      |  </body>
      |</html>
    """.stripMargin
    
    assertNoDiff(generated, expected)
  }
}

Exception Assertions

Methods for testing that specific exceptions are thrown with optional message validation.

/**
 * Assert that a specific exception type is thrown
 * @param body The code that should throw an exception
 * @return The caught exception for further inspection
 */
def intercept[T <: Throwable](body: => Any)(implicit T: ClassTag[T], loc: Location): T

/**
 * Assert that a specific exception with a specific message is thrown
 * @param expectedExceptionMessage The expected exception message
 * @param body The code that should throw an exception
 * @return The caught exception for further inspection
 */
def interceptMessage[T <: Throwable](expectedExceptionMessage: String)(body: => Any)(implicit T: ClassTag[T], loc: Location): T

Usage Examples:

class ExceptionExamples extends FunSuite {
  test("exception handling") {
    intercept[ArithmeticException] {
      10 / 0
    }
    
    val exception = intercept[IllegalArgumentException] {
      validateAge(-5)
    }
    assert(exception.getMessage.contains("negative"))
  }
  
  test("exception with specific message") {
    interceptMessage[IllegalStateException]("Service not initialized") {
      service.process()
    }
  }
}

Explicit Failures

Methods for explicitly failing tests with custom messages and context.

/**
 * Explicitly fail a test with a message and cause
 * @param message The failure message
 * @param cause The underlying exception that caused the failure
 */
def fail(message: String, cause: Throwable)(implicit loc: Location, diffOptions: DiffOptions): Nothing

/**
 * Explicitly fail a test with a message and clues
 * @param message The failure message
 * @param clues Additional debugging context
 */
def fail(message: String, clues: Clues = new Clues(Nil))(implicit loc: Location, diffOptions: DiffOptions): Nothing

/**
 * Fail with comparison context for IDE integration
 * @param message The failure message
 * @param obtained The actual value
 * @param expected The expected value
 * @param clues Additional debugging context
 */
def failComparison(message: String, obtained: Any, expected: Any, clues: Clues = new Clues(Nil))(implicit loc: Location, diffOptions: DiffOptions): Nothing

/**
 * Fail the entire test suite
 * @param message The failure message
 * @param clues Additional debugging context
 */
def failSuite(message: String, clues: Clues = new Clues(Nil))(implicit loc: Location, diffOptions: DiffOptions): Nothing

Usage Examples:

class FailureExamples extends FunSuite {
  test("conditional failure") {
    val result = complexOperation()
    if (!result.isValid) {
      fail(s"Operation failed: ${result.error}")
    }
  }
  
  test("failure with comparison") {
    val obtained = parseJson(input)
    val expected = ExpectedResult(...)
    
    if (obtained != expected) {
      failComparison("JSON parsing mismatch", obtained, expected)
    }
  }
}

Debugging Support

Utilities for adding context and debugging information to test failures.

/**
 * Add a debugging clue to a value
 * @param c The clue containing debug information
 * @return The original value with attached debugging context
 */
def clue[T](c: Clue[T]): T

/**
 * Create a collection of clues for debugging
 * @param clue Variable number of clues to combine
 * @return Combined clues for debugging context
 */
def clues(clue: Clue[_]*): Clues

/**
 * Print a value using the configured printer
 * @param clue The value to print
 * @return String representation of the value
 */
def munitPrint(clue: => Any): String

/**
 * Get the current printer instance
 * @return The configured printer for formatting output
 */
def printer: Printer

/**
 * Check if ANSI colors are enabled for output
 */
def munitAnsiColors: Boolean

Usage Examples:

class DebuggingExamples extends FunSuite {
  test("with debugging clues") {
    val input = getData()
    val result = clue(processData(clue(input)))
    
    assertEquals(result.status, "success")
  }
  
  test("multiple clues") {
    val user = getUser()
    val permissions = getPermissions(user)
    
    assert(
      hasAccess(user, resource),
      clues(
        clue(user),
        clue(permissions),
        clue(resource)
      )
    )
  }
}