class TestSuite

Primary class for unit testing.

Override and register unit tests in constructor then run the tests using the desired method of output.

Public

Methods

~TestSuite

virtual ~TestSuite() noexcept = default

Run

void Run(TestOutput &output)

Runs all the tests in the suite (and sub-suites).

Tests results are reported to the provided output class.

Add

void Add(const SPtr<TestSuite> &suite)

Adds a new child suite to this suite.

This method allows you to group suites and execute them all at once.

Internal

Methods

Assertment

void Assertment(bool success, const String &desc, const String &file, long line)

Reports success or failure depending on the result of an expression.

success
If true success is reported, otherwise failure.
desc
Message describing the nature of the failure.
file
Name of the source code file the assert originates from.
line
Line number at which the assert was triggered at.

Protected

Constructors

TestSuite

TestSuite(const String &name = "TestSuite")

Methods

StartUp

virtual void StartUp()

Called right before any tests are ran.

ShutDown

virtual void ShutDown()

Called after all tests and child suite's tests are ran.

GetLogMode

virtual LogMode GetLogMode() const

Override to specify log handling mode for this suite.

Default is Strict (fail on unexpected warnings/errors).

AddTest

void AddTest(Func test, const String &name)

Register a new unit test.

test
Function to call in order to execute the test.
name
Name of the test we can use for referencing it later.

Private

Methods

OnLogEntry

bool OnLogEntry(const String &message, LogVerbosity verbosity, const char *categoryName)

Log callback handler.

VerifyUnhandledLogs

void VerifyUnhandledLogs()

Verify any unhandled warnings/errors at end of test.

RegisterLogScope

void RegisterLogScope(LoggingScope *scope)

Register/unregister log scopes (called by LoggingScope).

UnregisterLogScope

void UnregisterLogScope(LoggingScope *scope)

Fields

mSuiteName

String mSuiteName

mTests

Vector<TestEntry> mTests

mSuites

Vector<SPtr<TestSuite>> mSuites

mOutput

TestOutput * mOutput

mActiveTestName

String mActiveTestName

mFailureCount

u32 mFailureCount

mCapturedLogs

Vector<LogEntry> mCapturedLogs

Logs captured during current test.

mActiveLogScopes

Vector<LoggingScope *> mActiveLogScopes

Active log scopes (stack - most recent first).

mLogCaptureActive

bool mLogCaptureActive

True if log capture is currently active.