class test_module


template <
    typename T
>
class test_module

Description

This class template represents a test module. A test module is an object containing functions that exercise, or test some piece of code, most commonly a class.

The general approach to testing adopted in CCL is to subclass test_module and implement one member function per unit test, construct this test_module subclass with an initializer list of function pointers referencing each member function containing a unit test, and then call the run_tests function to run all the tests. The return value of run_tests is then returned by the main function of the test program. The return value is the number of unit tests that failed, which is zero when all tests succeed.

Public Aliases

using inner_test_module_type = T

The inner test module type, that is, the test_module subclass.

using test_function_pointer = bool (inner_test_module_type::*)()

Gives a name to the signature of a test function so that corresponding function pointers can be written more clearly.

Public Member Functions

explicit
test_module (
    std::vector<test_function_pointer> test_functions
)
noexcept

Constructs a test module aware of the provided test functions.

Parameters:
  • test_functions:

    The pointers to the test functions that this test_module will run when run_tests is called.

test_module (
    const test_module& other
)

Copy-constructs a test_module from an existing one.

Parameters:
  • other:

    The test_module to copy from.

test_module&
operator = (
    const test_module& other
)

Copy-assigns a test_module into this one.

Parameters:
  • other:

    The test_module to copy from.

test_module (
    test_module&& other
)
noexcept

Move-constructs a test_module from an existing one.

Parameters:
  • other:

    The test_module to move from.

test_module&
operator = (
    test_module&& other
)
noexcept

Move-assigns a test_module into this one.

Parameters:
  • other:

    The test_module to move from.

unsigned int
get_message_count ()
const noexcept

Returns the number of messages in the message queue.

int
run_tests ()
noexcept

Runs all registered tests in this test module and returns the number of tests that failed.

void
start_test (
    const char* test_name
)
noexcept

Announces the test that is just starting

Parameters:
  • test_name:

    The name of the test that is just starting.

void
end_stage ()
noexcept

Ends the current stage and counts it as successful.

void
push_message (
    message message_value
)
noexcept

Pushes a message onto the message queue.

Parameters:
  • message_value:

    The message to push onto the message queue.

message
pop_message ()
noexcept

Pops a message from the message queue and returns it. If the message queue was empty, an empty message is returned.

void
clear_message_queue ()
noexcept

Removes all messages in the message queue.

std::ostream&
log_info ()
const noexcept

Returns an output stream that can be used to log informational messages.

std::ostream&
log_error ()
const noexcept

Returns an output stream that can be used to log error messages.



Copyright © 2022-2025 Daniel T. McGinnis

CCL was first published in 2022, and is still actively maintained.

This website was first published in 2022, and is still actively maintained.

This specific web page was first published in 2023.