Header menu logo testify

Operator Cheat Sheet

Operators in Testify are deliberately thin:

They are the surface syntax of the Testify DSL, not a separate engine. If you want the full model behind that statement, read DSL and Mental Model first or come back to it after this page.

If an operator stops being readable, switch back to the named API.

Assert Operators

Operator Meaning Named Equivalent Returns Best Used When
|>?Apply one reusable expectationAssert.should expectation exprunitYou already have an expectation value
>>?Apply one expectation and keep the quotationAssert.should expectation expr plus chainingthe original quotationYou want left-to-right chained checks
=?Equality assertionAssert.should (AssertExpectation.equalTo value) exprunitSimple direct equality
<>?Non-equality assertionAssert.should (AssertExpectation.notEqualTo value) exprunitSimple direct inequality
<?Less-than assertionAssert.should (AssertExpectation.lessThan value) exprunitSimple comparison
<=?Less-than-or-equal assertionAssert.should (AssertExpectation.lessThanOrEqualTo value) exprunitSimple comparison
>?Greater-than assertionAssert.should (AssertExpectation.greaterThan value) exprunitSimple comparison
>=?Greater-than-or-equal assertionAssert.should (AssertExpectation.greaterThanOrEqualTo value) exprunitSimple comparison
^?The quoted expression should throwAssert.should AssertExpectation.throwsAny exprunitException-oriented tests
^!?The quoted expression should not throwAssert.should AssertExpectation.doesNotThrow exprunitMaking exception-freedom explicit
?Boolean expression should be trueAssert.should AssertExpectation.isTrue exprunitShort direct boolean tests
!?Boolean expression should be falseAssert.should AssertExpectation.isFalse exprunitShort direct boolean tests
||?Any expectation from a sequence may passAssert.should (AssertExpectation.any expectations) exprunitYou have many alternatives
&&?All expectations from a sequence must passAssert.should (AssertExpectation.all expectations) exprunitYou have many required expectations

Check Operators

Operator Meaning Named Equivalent Returns Best Used When
|=>Default fail-fast equality check against a referenceCheck.should(CheckExpectation.equalToReference, reference, expr)unitThe standard reference-style property test
|=>>Same as |=>, but keep the quotationCheck.should(...) plus chainingthe original quotationYou want chain-friendly property syntax
|?>Callback-built fail-fast propertyCheck.shouldBy(buildProperty, CheckExpectation.isTrue, (fun _ -> true), expr)unitYou need custom quantification or dependent generation

Composition Operators

The composition operators are shared expectation-level building blocks.

Operator Meaning Named Equivalent Notes
<|>Logical OR of expectationsorElseChainable; use any for longer alternative lists
<&>Logical AND of expectationsandAlsoChainable; use all for longer required lists

Chainable Composition Examples

Short OR-chain:

let relaxedYes =
    AssertExpectation.equalTo "yes"
    <|> AssertExpectation.equalTo "y"
    <|> AssertExpectation.equalTo "true"

Short AND-chain:

let bounded =
    AssertExpectation.greaterThanOrEqualTo 0
    <&> AssertExpectation.lessThan 10
    <&> AssertExpectation.notEqualTo 7

On the property side:

let forgivingRelation =
    CheckExpectation.equalToReference
    <|> CheckExpectation.throwsSameExceptionType
    <|> CheckExpectation.equalByKey String.length 5

When To Prefer Named APIs

Prefer named APIs over operators when:

Operators are there to reduce ceremony, not to hide the structure of the test.

val relaxedYes: obj
val bounded: '_arg3
val forgivingRelation: '_arg3
module String from Microsoft.FSharp.Core
val length: str: string -> int

Type something to start searching.