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 builds and runs a complete test project.
The package’s three modules — Exact, Strict, and Permissive — 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 | 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 | case-sensitive | evaluated as if the comparison were written directly in twinBASIC code; object default members are not evaluated |
| Permissive | 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 / IsNotNull assertions rather than AreEqual(..., Null).
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)].
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 and the Debug.Assert statement do. A test runner therefore needs to build the project with debug enabled.
Modules
- Exact – strictest comparisons; datatypes must match and conversions never happen
- Strict – case-sensitive strings, but otherwise equality matches a direct comparison in twinBASIC code
- Permissive – 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 – asserts that Actual is equal to Expected under strictest semantics; datatypes must match and no implicit conversions occur
- AreNotEqual – asserts that Actual is not equal to Expected under strictest semantics; datatypes must match and no implicit conversions occur
- AreNotSame – asserts that Actual and Expected refer to different objects
- AreSame – asserts that Actual and Expected refer to the same object
- Fail – unconditionally records a test failure
- Inconclusive – records the test as inconclusive — neither a pass nor a failure
- IsFalse – asserts that Condition evaluates to False
- IsNothing – asserts that Value is the Nothing object reference
- IsNotNothing – asserts that Value refers to an object and is not Nothing
- IsNotNull – asserts that Value is not the Null value of a Variant
- IsNull – asserts that Value is the Null value of a Variant
- IsTrue – asserts that Condition evaluates to True
- NotSequenceEquals – asserts that Actual and Expected differ in length or in at least one element
- SequenceEquals – asserts that Actual and Expected contain the same elements in the same order
- Succeed – records that the test reached this point without failure
Permissive
- AreEqual – asserts that Actual is equal to Expected with case-insensitive strings and numeric promotion
- AreNotEqual – asserts that Actual is not equal to Expected with case-insensitive strings and numeric promotion
- AreNotSame – asserts that Actual and Expected refer to different objects
- AreSame – asserts that Actual and Expected refer to the same object
- Fail – unconditionally records a test failure
- Inconclusive – records the test as inconclusive — neither a pass nor a failure
- IsFalse – asserts that Condition evaluates to False
- IsNothing – asserts that Value is the Nothing object reference
- IsNotNothing – asserts that Value refers to an object and is not Nothing
- IsNotNull – asserts that Value is not the Null value of a Variant
- IsNull – asserts that Value is the Null value of a Variant
- IsTrue – asserts that Condition evaluates to True
- NotSequenceEquals – asserts that Actual and Expected differ in length or in at least one element
- SequenceEquals – asserts that Actual and Expected contain the same elements in the same order
- Succeed – records that the test reached this point without failure
Strict
- AreEqual – asserts that Actual is equal to Expected with case-sensitive strings and normal twinBASIC equality
- AreNotEqual – asserts that Actual is not equal to Expected with case-sensitive strings and normal twinBASIC equality
- AreNotSame – asserts that Actual and Expected refer to different objects
- AreSame – asserts that Actual and Expected refer to the same object
- Fail – unconditionally records a test failure
- Inconclusive – records the test as inconclusive — neither a pass nor a failure
- IsFalse – asserts that Condition evaluates to False
- IsNothing – asserts that Value is the Nothing object reference
- IsNotNothing – asserts that Value refers to an object and is not Nothing
- IsNotNull – asserts that Value is not the Null value of a Variant
- IsNull – asserts that Value is the Null value of a Variant
- IsTrue – asserts that Condition evaluates to True
- NotSequenceEquals – asserts that Actual and Expected differ in length or in at least one element
- SequenceEquals – asserts that Actual and Expected contain the same elements in the same order
- Succeed – records that the test reached this point without failure