CustomTest

Factory

Create #

Build and configure a harness instance

Signature:

Public Function Create(ByVal targetWorkbook As workbook, _
                       Optional ByVal outputSheetName As String = vbNullString) As CustomTest

Parameters:

  • targetWorkbook: Workbook under test that receives logging output
  • outputSheetName: Optional name of the worksheet used for results

Returns: CustomTest harness ready for use


Public members

Configure #

Configure the harness with the workbook and target sheet

Signature:

Public Sub Configure(ByVal targetWorkbook As workbook, _
                     Optional ByVal outputSheetName As String = vbNullString)

Parameters:

  • targetWorkbook: Workbook that supplies and receives output
  • outputSheetName: Optional sheet name where results will be written

Throws:

  • ProjectError.InvalidArgument When workbook reference is invalid

ReleaseResources #

Clear references and reset harness state

Signature:

Public Sub ReleaseResources()

SetModuleName #

Set the VBA module name used in rendered output

Signature:

Public Sub SetModuleName(ByVal moduleName As String)

Parameters:

  • moduleName: Name displayed in result tables

SetTestName #

Set the pending test name for subsequent assertions

Signature:

Public Sub SetTestName(ByVal testName As String)

Parameters:

  • testName: Descriptive identifier of the current test

SetTestSubtitle #

Set an optional subtitle for the pending test

Signature:

Public Sub SetTestSubtitle(ByVal testSubtitle As String)

Parameters:

  • testSubtitle: Additional context for the test case

BeginTest #

Persist previous checking and start logging a new test

Signature:

Public Sub BeginTest(Optional ByVal resetNames As Boolean = False)

ResetInstance #

Reset

Clear current checking and accumulated results

Signature:

Public Sub ResetInstance()

FlushCurrentTest #

Persist active checking and return accumulated results

Signature:

Public Function FlushCurrentTest(Optional ByVal resetNames As Boolean = True) As BetterArray

Parameters:

  • resetNames: Optional Boolean specifying whether to reset names after clearing

Returns: BetterArray containing all persisted checkings


Flush #

Persist active checking without returning the accumulated results

Signature:

Public Sub Flush(Optional ByVal resetNames As Boolean = True)

Parameters:

  • resetNames: Optional Boolean specifying whether to reset names after clearing

Results #

Clone accumulated checking results

Signature:

Public Function Results() As BetterArray

Returns: BetterArray clone of collected checkings


PrintResults #

Write the results to a worksheet using CheckingOutput

Signature:

Public Sub PrintResults(Optional ByVal outputSheetName As String = vbNullString)

Parameters:

  • outputSheetName: Optional override for worksheet name

Depends on:

  • CheckingOutput

AreEqual #

Log an assertion comparing expected and actual values

Signature:

Public Sub AreEqual(expected As Variant, _
                    actual As Variant, _
                       ByVal message As String)

Parameters:

  • expected: Expected value
  • actual: Actual value
  • message: Message describing the assertion context

AreNotEqual #

Log an assertion confirming expected and actual values differ

Signature:

Public Sub AreNotEqual(expected As Variant, _
                       actual As Variant, _
                          ByVal message As String)

Parameters:

  • expected: Expected value
  • actual: Actual value
  • message: Message describing the assertion context

IsTrue #

Log that a boolean condition holds true

Signature:

Public Sub IsTrue(ByVal condition As Boolean, _
                      ByVal message As String)

Parameters:

  • condition: Condition to evaluate
  • message: Message describing the assertion context

IsFalse #

Log that a boolean condition evaluates to False

Signature:

Public Sub IsFalse(ByVal condition As Boolean, _
                       ByVal message As String)

Parameters:

  • condition: Condition to evaluate
  • message: Message describing the assertion context

ObjectExists #

Confirm an object reference exists and matches the expected type name

Signature:

Public Sub ObjectExists(ByVal instance As Object, _
                        ByVal expectedTypeName As String, _
                        ByVal message As String)

Parameters:

  • instance: Object reference to validate
  • expectedTypeName: Expected VBA type name
  • message: Message describing the assertion context

IsNothing #

Validate that an object reference is Nothing

Signature:

Public Sub IsNothing(ByVal instance As Object, ByVal message As String)

Parameters:

  • instance: Object reference to validate
  • message: Message describing the assertion context

IsNotNothing #

Validate that an object is not Nothing

Signature:

Public Sub IsNotNothing(ByVal instance As Object, ByVal message As String)

Parameters:

  • instance: Object reference to validate
  • message: Message describing the assertion context

LogFailure #

Log a failure message directly to the current checking

Signature:

Public Sub LogFailure(ByVal message As String)

Parameters:

  • message: Message describing the failure

Fail #

Log a failure message; alias of LogFailure for compatibility

Signature:

Public Sub Fail(ByVal message As String)

Parameters:

  • message: Message describing the failure

LogSuccesses #

Log a success message directly to the current checking

Signature:

Public Sub LogSuccesses(ByVal message As String)

Parameters:

  • message: Message describing the success

Internal members (not exported)

Public members

HeadlessRunActive #

True when a headless runner (OBTHeadless) is driving the suite

Signature:

Private Function HeadlessRunActive() As Boolean

Late-bound so this class carries no dependency on the runner: if the OBTHeadlessActive entry point is absent, Application.Run raises and we treat the run as interactive.

The call NAMES ITS WORKBOOK. An unqualified Application.Run resolves the procedure against the ACTIVE workbook, and a suite that leaves a workbook of its own open and on screen makes that some file carrying no code. The lookup then fails, and inside the Apple Events run VB macro call that failure is a NON-trappable -50: On Error Resume Next does not catch it, the macro dies and the whole headless run is lost with an empty results file. Naming the workbook that owns OBTHeadless takes the active workbook out of the question.


Internal helpers

InitialiseCurrentChecking #

Instantiate a fresh checking object for the active test

Signature:

Private Sub InitialiseCurrentChecking()

EnsureCurrentChecking #

Lazily initialise the current checking container

Signature:

Private Sub EnsureCurrentChecking()

ClearCurrentChecking #

Drop the current checking reference and optionally reset names

Signature:

Private Sub ClearCurrentChecking(Optional ByVal resetNames As Boolean = True)

Parameters:


PersistActiveChecking #

Store the active checking into the results buffer when it has entries

Signature:

Private Sub PersistActiveChecking(Optional ByVal resetNames As Boolean = False)

EnsureResults #

Create the BetterArray container when missing and return it

Signature:

Private Function EnsureResults() As BetterArray

Returns: BetterArray used to hold persisted checkings


LogEntry #

Append a formatted assertion outcome to the current checking

Signature:

Private Sub LogEntry(ByVal message As String, ByVal scope As Byte)

Parameters:


FormatSuccessMessage #

Build the message stored when an assertion succeeds

Signature:

Private Function FormatSuccessMessage(ByVal mess As String) As String

Parameters:

Returns: Formatted message prefixed with Success


BuildFailureMessage #

Build the failure message including expected and actual values

Signature:

Private Function BuildFailureMessage(ByVal message As String, _
                                     expected As Variant, _
                                     actual As Variant) As String

Parameters:

Returns: Failure message containing expected/actual details


ResolveTitle #

Normalise names used for modules and tests

Signature:

Private Function ResolveTitle(ByVal val As String) As String

Parameters:

Returns: Sanitised name or default label


ResolveFailurePrefix #

Normalize assertion failure prefix text

Signature:

Private Function ResolveFailurePrefix(ByVal mess As String) As String

Parameters:

Returns: Prefix used for failure messages


ResolveSheetName #

Normalise worksheet names used for output

Signature:

Private Function ResolveSheetName(ByVal shName As String) As String

Parameters:

Returns: Validated sheet name or default output sheet


PrintOutputWorksheet #

Retrieve or create the worksheet that receives test output

Signature:

Private Function PrintOutputWorksheet(ByVal targetWorkbook As workbook, _
                                 ByVal sheetName As String) As Worksheet

Parameters:

Returns: Worksheet ready for output


VariantsAreEqual #

Compare two Variant values using tolerant rules

Signature:

Private Function VariantsAreEqual(leftValue As Variant, _
                                  rightValue As Variant) As Boolean

Parameters:

Returns: True when the values are equal


VariantToString #

Convert a Variant into a readable String representation

Signature:

Private Function VariantToString(value As Variant) As String

Parameters:

Returns: String representation of the value


RaiseError #

Wrap Err.Raise to keep consistent error source

Signature:

Private Sub RaiseError(ByVal errorCode As ProjectError, ByVal description As String)

Parameters:


Used in (100 file(s))