# Assert Package

The **Assert** built-in package supplies the assertion functions used to write unit tests for twinBASIC code. Each assertion checks an expected condition. One that holds does nothing visible, so a test procedure that returns has passed. One that fails raises the run-time error **Assertion FAILED** (-353703420, `&HEAEAEA04`) at the call, and the IDE stops on that line --- even inside `On Error Resume Next`, which does not catch it. The expected value, the actual value and the optional message are not displayed, and nothing is written to the Debug Console. [Writing unit tests with Assert](/Tutorials/Testing-with-Assert.md) builds and runs a complete test project, and [shows the IDE stopped](/Tutorials/Testing-with-Assert.md#running-the-tests) at a failed assertion.

The package's three modules --- [**Exact**](/tB/Packages/Assert/Exact.md), [**Strict**](/tB/Packages/Assert/Strict.md), and [**Permissive**](/tB/Packages/Assert/Permissive.md) --- expose the same fifteen assertion functions; only the *comparison semantics* differ. Each flavour matches a different strictness level for equality evaluation.

| Module                       | String comparisons | Numeric and other comparisons                                                                                                                              |
|------------------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [**Exact**](/tB/Packages/Assert/Exact.md)           | case-sensitive     | no implicit conversions; datatypes must match exactly (`5` ≠ `5.0`); `vbNullString` is distinct from `""`; `Empty` is distinct from `0`, `False`, and `""`; object default members are *not* evaluated |
| [**Strict**](/tB/Packages/Assert/Strict.md)         | case-sensitive     | evaluated as if the comparison were written directly in twinBASIC code; object default members are *not* evaluated                                         |
| [**Permissive**](/tB/Packages/Assert/Permissive.md) | case-insensitive   | evaluated as if the comparison were written directly in twinBASIC code                                                                                     |

`Null` is never considered equal to anything --- not even to itself --- under any of the three flavours. To test for **Null** explicitly, use the [**IsNull**](/tB/Packages/Assert/Exact.md#isnull) / [**IsNotNull**](/tB/Packages/Assert/Exact.md#isnotnull) assertions rather than `AreEqual(..., Null)`.

```tb check_build
Sub TestStringReverse()
    Assert.Strict.AreEqual "olleh", StrReverse("hello")
    Assert.Strict.AreEqual "", StrReverse("")
End Sub
```

## Calling convention

**Every call carries two qualifiers, and both are required.** The package namespace `Assert` comes first, because a package's members are reached through its namespace symbol; `VBA`, `VBRUN` and `VB` resolve unqualified only because every project references them, and **Assert** is referenced on demand. The module name comes next, because every member of every module is tagged `[MustBeQualified(True)]`.

```tb inert=contrast
Assert.Strict.IsTrue x > 0   ' OK
Strict.IsTrue x > 0          ' compile error -- the package namespace is missing
Assert.IsTrue x > 0          ' compile error -- the module name is missing
IsTrue x > 0                 ' compile error -- both are missing
```

## Debug-only

Every assertion is tagged `[DebugOnly(True)]` --- the calls compile to *nothing* in release builds, in the same way that [**Debug.Print**](/tB/Core/Print.md) and the **Debug.Assert** statement do. A test runner therefore needs to build the project with debug enabled.

## Modules

- [Exact](/tB/Packages/Assert/Exact.md) -- strictest comparisons; datatypes must match and conversions never happen
- [Strict](/tB/Packages/Assert/Strict.md) -- case-sensitive strings, but otherwise equality matches a direct comparison in twinBASIC code
- [Permissive](/tB/Packages/Assert/Permissive.md) -- case-insensitive strings; otherwise equality matches a direct comparison in twinBASIC code

## Members

Each module exposes the same fifteen functions. See the per-module pages for the full signatures and the comparison semantics that apply to each member.

### Exact

- [AreEqual](/tB/Packages/Assert/Exact.md#areequal) -- asserts that *Actual* is equal to *Expected* under strictest semantics; datatypes must match and no implicit conversions occur
- [AreNotEqual](/tB/Packages/Assert/Exact.md#arenotequal) -- asserts that *Actual* is not equal to *Expected* under strictest semantics; datatypes must match and no implicit conversions occur
- [AreNotSame](/tB/Packages/Assert/Exact.md#arenotsame) -- asserts that *Actual* and *Expected* refer to different objects
- [AreSame](/tB/Packages/Assert/Exact.md#aresame) -- asserts that *Actual* and *Expected* refer to the same object
- [Fail](/tB/Packages/Assert/Exact.md#fail) -- unconditionally records a test failure
- [Inconclusive](/tB/Packages/Assert/Exact.md#inconclusive) -- records the test as inconclusive --- neither a pass nor a failure
- [IsFalse](/tB/Packages/Assert/Exact.md#isfalse) -- asserts that *Condition* evaluates to **False**
- [IsNothing](/tB/Packages/Assert/Exact.md#isnothing) -- asserts that *Value* is the **Nothing** object reference
- [IsNotNothing](/tB/Packages/Assert/Exact.md#isnotnothing) -- asserts that *Value* refers to an object and is not **Nothing**
- [IsNotNull](/tB/Packages/Assert/Exact.md#isnotnull) -- asserts that *Value* is not the **Null** value of a **Variant**
- [IsNull](/tB/Packages/Assert/Exact.md#isnull) -- asserts that *Value* is the **Null** value of a **Variant**
- [IsTrue](/tB/Packages/Assert/Exact.md#istrue) -- asserts that *Condition* evaluates to **True**
- [NotSequenceEquals](/tB/Packages/Assert/Exact.md#notsequenceequals) -- asserts that *Actual* and *Expected* differ in length or in at least one element
- [SequenceEquals](/tB/Packages/Assert/Exact.md#sequenceequals) -- asserts that *Actual* and *Expected* contain the same elements in the same order
- [Succeed](/tB/Packages/Assert/Exact.md#succeed) -- records that the test reached this point without failure

### Permissive

- [AreEqual](/tB/Packages/Assert/Permissive.md#areequal) -- asserts that *Actual* is equal to *Expected* with case-insensitive strings and numeric promotion
- [AreNotEqual](/tB/Packages/Assert/Permissive.md#arenotequal) -- asserts that *Actual* is not equal to *Expected* with case-insensitive strings and numeric promotion
- [AreNotSame](/tB/Packages/Assert/Permissive.md#arenotsame) -- asserts that *Actual* and *Expected* refer to different objects
- [AreSame](/tB/Packages/Assert/Permissive.md#aresame) -- asserts that *Actual* and *Expected* refer to the same object
- [Fail](/tB/Packages/Assert/Permissive.md#fail) -- unconditionally records a test failure
- [Inconclusive](/tB/Packages/Assert/Permissive.md#inconclusive) -- records the test as inconclusive --- neither a pass nor a failure
- [IsFalse](/tB/Packages/Assert/Permissive.md#isfalse) -- asserts that *Condition* evaluates to **False**
- [IsNothing](/tB/Packages/Assert/Permissive.md#isnothing) -- asserts that *Value* is the **Nothing** object reference
- [IsNotNothing](/tB/Packages/Assert/Permissive.md#isnotnothing) -- asserts that *Value* refers to an object and is not **Nothing**
- [IsNotNull](/tB/Packages/Assert/Permissive.md#isnotnull) -- asserts that *Value* is not the **Null** value of a **Variant**
- [IsNull](/tB/Packages/Assert/Permissive.md#isnull) -- asserts that *Value* is the **Null** value of a **Variant**
- [IsTrue](/tB/Packages/Assert/Permissive.md#istrue) -- asserts that *Condition* evaluates to **True**
- [NotSequenceEquals](/tB/Packages/Assert/Permissive.md#notsequenceequals) -- asserts that *Actual* and *Expected* differ in length or in at least one element
- [SequenceEquals](/tB/Packages/Assert/Permissive.md#sequenceequals) -- asserts that *Actual* and *Expected* contain the same elements in the same order
- [Succeed](/tB/Packages/Assert/Permissive.md#succeed) -- records that the test reached this point without failure

### Strict

- [AreEqual](/tB/Packages/Assert/Strict.md#areequal) -- asserts that *Actual* is equal to *Expected* with case-sensitive strings and normal twinBASIC equality
- [AreNotEqual](/tB/Packages/Assert/Strict.md#arenotequal) -- asserts that *Actual* is not equal to *Expected* with case-sensitive strings and normal twinBASIC equality
- [AreNotSame](/tB/Packages/Assert/Strict.md#arenotsame) -- asserts that *Actual* and *Expected* refer to different objects
- [AreSame](/tB/Packages/Assert/Strict.md#aresame) -- asserts that *Actual* and *Expected* refer to the same object
- [Fail](/tB/Packages/Assert/Strict.md#fail) -- unconditionally records a test failure
- [Inconclusive](/tB/Packages/Assert/Strict.md#inconclusive) -- records the test as inconclusive --- neither a pass nor a failure
- [IsFalse](/tB/Packages/Assert/Strict.md#isfalse) -- asserts that *Condition* evaluates to **False**
- [IsNothing](/tB/Packages/Assert/Strict.md#isnothing) -- asserts that *Value* is the **Nothing** object reference
- [IsNotNothing](/tB/Packages/Assert/Strict.md#isnotnothing) -- asserts that *Value* refers to an object and is not **Nothing**
- [IsNotNull](/tB/Packages/Assert/Strict.md#isnotnull) -- asserts that *Value* is not the **Null** value of a **Variant**
- [IsNull](/tB/Packages/Assert/Strict.md#isnull) -- asserts that *Value* is the **Null** value of a **Variant**
- [IsTrue](/tB/Packages/Assert/Strict.md#istrue) -- asserts that *Condition* evaluates to **True**
- [NotSequenceEquals](/tB/Packages/Assert/Strict.md#notsequenceequals) -- asserts that *Actual* and *Expected* differ in length or in at least one element
- [SequenceEquals](/tB/Packages/Assert/Strict.md#sequenceequals) -- asserts that *Actual* and *Expected* contain the same elements in the same order
- [Succeed](/tB/Packages/Assert/Strict.md#succeed) -- records that the test reached this point without failure
