Header menu logo testify

Assert Module

Types and nested modules

Type/Module Description

Collect

Helpers for collecting multiple independent assertion results.

Collector

Opaque collector that stores multiple assertion results for later aggregation.

Functions and values

Function or value Description

Assert.assertPassed result

Full Usage: Assert.assertPassed result

Parameters:

Raises when the supplied assertion result is not Passed.

result : AssertResult

The result to validate.

Exception Raised when result is Failed. The exception message contains the rendered assertion failure.

Assert.result expectation actual

Full Usage: Assert.result expectation actual

Parameters:
    expectation : AssertExpectation<'T> - The reusable expectation to verify.
    actual : Expr<'T> - The quoted expression under test.

Returns: AssertResult Passed when the quoted expression satisfies the expectation; otherwise a structured Failed result describing the mismatch.

Evaluates an assertion expectation against a quoted expression.

The quotation is evaluated by this call. Use result when you want to inspect the result yourself instead of failing immediately.

expectation : AssertExpectation<'T>

The reusable expectation to verify.

actual : Expr<'T>

The quoted expression under test.

Returns: AssertResult

Passed when the quoted expression satisfies the expectation; otherwise a structured Failed result describing the mismatch.

Example

 let result =
     <@ 1 + 2 @>
     |> Assert.result (AssertExpectation.equalTo 3)
val result: obj

Assert.resultAsync expectation actual

Full Usage: Assert.resultAsync expectation actual

Parameters:
    expectation : AssertExpectation<'T> - The reusable expectation to verify.
    actual : Expr - The quoted asynchronous expression under test, typically producing Async<'T>, Task<'T>, or another awaitable value supported by Testify.

Returns: Task<AssertResult> A task that completes with Passed when the asynchronous computation satisfies the expectation, or Failed when it does not.

Evaluates an asynchronous assertion and returns the result inside a task.

The quoted asynchronous computation is awaited by this call.

expectation : AssertExpectation<'T>

The reusable expectation to verify.

actual : Expr

The quoted asynchronous expression under test, typically producing Async<'T>, Task<'T>, or another awaitable value supported by Testify.

Returns: Task<AssertResult>

A task that completes with Passed when the asynchronous computation satisfies the expectation, or Failed when it does not.

Example

 let! result =
     Assert.resultAsync
         (AssertExpectation.equalTo 3)
         <@ task { return 1 + 2 } @>
val task: TaskBuilder

Assert.resultNamed test expectation actual

Full Usage: Assert.resultNamed test expectation actual

Parameters:
    test : string - The human-readable label to show instead of the rendered quotation.
    expectation : AssertExpectation<'T> - The reusable expectation to verify.
    actual : Expr<'T> - The quoted expression under test.

Returns: AssertResult Passed when the quoted expression satisfies the expectation; otherwise a structured Failed result that uses test in its report output.

Evaluates an assertion like result, but uses the supplied test label in failure output.

The quotation is still evaluated by this call even when a custom label is supplied.

test : string

The human-readable label to show instead of the rendered quotation.

expectation : AssertExpectation<'T>

The reusable expectation to verify.

actual : Expr<'T>

The quoted expression under test.

Returns: AssertResult

Passed when the quoted expression satisfies the expectation; otherwise a structured Failed result that uses test in its report output.

Example

 let result =
     Assert.resultNamed
         "student implementation"
         (AssertExpectation.equalTo 42)
         <@ answer() @>
val result: obj

Assert.should expectation actual

Full Usage: Assert.should expectation actual

Parameters:
    expectation : AssertExpectation<'T> - The reusable expectation to verify.
    actual : Expr<'T> - The quoted expression under test.

Runs an assertion and raises immediately when it fails.

The quotation is evaluated by this call.

expectation : AssertExpectation<'T>

The reusable expectation to verify.

actual : Expr<'T>

The quoted expression under test.

Exception Raised when the quoted expression does not satisfy expectation.
Example

 <@ "Mini" + "Lib" @>
 |> Assert.should (AssertExpectation.equalTo "MiniLib")

Assert.shouldAsync expectation actual

Full Usage: Assert.shouldAsync expectation actual

Parameters:
    expectation : AssertExpectation<'T> - The reusable expectation to verify.
    actual : Expr - The quoted asynchronous expression under test.

Returns: Task A task that completes when the assertion has finished running.

Runs an asynchronous assertion and raises immediately when it fails.

expectation : AssertExpectation<'T>

The reusable expectation to verify.

actual : Expr

The quoted asynchronous expression under test.

Returns: Task

A task that completes when the assertion has finished running.

Exception Raised when the awaited computation does not satisfy expectation.
Example

 do!
     Assert.shouldAsync
         (AssertExpectation.equalTo 3)
         <@ task { return 1 + 2 } @>
val task: TaskBuilder

Assert.toDisplayString result

Full Usage: Assert.toDisplayString result

Parameters:
Returns: string The configured rendered representation suitable for terminal output or test failures.

Renders an assertion result using the current Testify report options.

result : AssertResult

The assertion result to render.

Returns: string

The configured rendered representation suitable for terminal output or test failures.

Assert.toDisplayStringWith options result

Full Usage: Assert.toDisplayStringWith options result

Parameters:
Returns: string The configured rendered representation suitable for terminal output or test failures.

Renders an assertion result with the supplied report options.

options : TestifyReportOptions

The report rendering options to use.

result : AssertResult

The assertion result to render.

Returns: string

The configured rendered representation suitable for terminal output or test failures.

Assert.toFailureReport result

Full Usage: Assert.toFailureReport result

Parameters:
    result : AssertResult - The assertion result to translate.

Returns: TestifyFailureReport option Some failure report when result is Failed; otherwise None.

Converts a failed assertion into a structured Testify failure report.

result : AssertResult

The assertion result to translate.

Returns: TestifyFailureReport option

Some failure report when result is Failed; otherwise None.

Type something to start searching.