fcfTest is a lightweight, header-only unit testing framework for C++, designed for maximum ease of integration and efficient debugging.
The library is delivered as a single header file, eliminating the need for complex build or linking configuration. Its key advantage is the intelligent macro FCF_TEST, which automatically prints the names and current values of all passed variables when a test fails, significantly speeding up error detection.
In addition to basic checks, fcfTest provides a built-in logger with configurable verbosity levels, benchmarking tools (measuring execution time), and a flexible command-line test management system. Tests are organized into a hierarchy (Part → Group → Test), allowing you to run only the necessary sets of checks, specify the execution order, and ignore certain blocks without recompiling the code.
Ideal for small projects, microservices, and situations where rapid implementation of robust testing without unnecessary dependencies is required.
Pages
Enums
fcf::NTest::ECmdMode - Contains the result specified by the user via the command line of the
fcf::NTest::cmdRun function.
fcf::NTest::ELogLevel - Enumeration of available logging severity levels used to filter diagnostic output
Macros
- This macro is used to enable the implementation section within the header file fcfTest/test.hpp.
- This macro is declared when building a DLL (shared library) to tell the compiler that functions should be exported.
- This macro is declared when importing fcfTest functions from a shared library (if you built fcfTest in a separate library) to inform the compiler that the functions should be imported.
FCF_TEST_DECLARE(
const char* am_part,
const char* am_group,
const char* am_test)
- Declares a test and takes three parameters that organize the test tree (Parts -> Groups -> Tests)
FCF_TEST(
bool am_expression, [
mixed am_displayVariable...])
- The basic assertion macro. Checks a logical expression and, if it fails, throws std::runtime_error with a detailed report: the original expression, file, line of code, and the values of the passed variables.
- Registers a deterministic execution priority for a specific test part. Lower integer values indicate higher priority (run earlier).
- Registers a deterministic execution priority for a specific test group. Lower integer values indicate higher priority (run earlier).
- Registers a deterministic execution priority for a specific test. Lower integer values indicate higher priority (run earlier).
Classes
- A high-resolution timer utility for benchmarking code execution. It supports both manual timing control and automated execution of functors over a specified number of iterations.
- This structure holds the configuration for running tests. It is populated automatically by the command line parser but can be used manually.
- A configurable logging utility providing multiple severity levels and customizable output formatting via static prefixes or functional callbacks
Functions
- Provides global access to the singleton logger instance for configurable, multi-level diagnostic output with support for custom static and dynamic prefixes
fcf::NTest::ECmdMode
fcf::NTest::cmdRun(
fcf::NTest::Options& a_dstOptions,
int a_argc,
const char*
const* a_argv,
fcf::NTest::ECmdRunMode a_runMode,
bool* a_errorPtr
= 0)
fcf::NTest::ECmdMode
fcf::NTest::cmdRun(
int a_argc,
const char*
const* a_argv,
fcf::NTest::ECmdRunMode a_runMode,
bool* a_errorPtr
= 0)
- The central function for executing the test suite. It performs command-line argument parsing, test filtering, and execution according to the specified run mode.
- Outputs help information regarding available command-line arguments for controlling the testing process to the standard output (stdout)
- Outputs a hierarchical list of all registered tests to the standard output (stdout), following the structure: Part > Group > Test.
void
fcf::NTest::run(
const fcf::NTest::Options& a_options,
bool* a_errorPtr
= 0)
- Executes the selected tests based on the provided fcf::NTest::Options configuration. If an error occurs during test execution, the error state is reported via the provided pointer.
- Returns a reference to the output stream for fatal-level log messages. This level is used for critical failures that require immediate attention.
- Returns a reference to the output stream for error-level log messages. This level is used to report significant issues that do not necessarily terminate the application
- Returns a reference to the output stream for warning-level log messages. This level is used for warnings that require immediate attention.
- Returns a reference to the output stream for attention-level log messages. This level is used for important message that require attention.
- Returns a reference to the output stream for default level log messages. This level is used for simple message that require attention.
- Returns a reference to the output stream for info level log messages. This level is used for message with a secondary importance
- Returns a reference to the output stream for debug log messages. This logging level is used to output the debugging mesasge.
- Returns a reference to the output stream for trace log messages. This logging level is used to extract tracing data.