FCF 2.0 development in progress...
> >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

Package fcfTest

fcfTest is a lightweight, header-only unit testing framework for C++(>=11), 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.

Github: https://github.com/fcf-framework/fcfTest

Pages
Enums
fcf::NTest::ECmdMode - Contains the result specified by the user via the command line of the fcf::NTest::cmdRun function.
fcf::NTest::ECmdRunMode - This enum dictates how fcf::NTest::cmdRun behaves during parsing
fcf::NTest::ELogLevel - Enumeration of available logging severity levels used to filter diagnostic output
fcf::NTest::ELogMessageCategory - Defines bitmask-based categories for log messages, allowing for granular filtering and specialized formatting of diagnostic output.
fcf::NTest::EFixtureLevel - Defines the launch zone for the fixture.
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_DEFINE(const char* am_part, const char* am_group, const char* am_test)
FCF_TEST_DEFINE(const char* am_part, const char* am_group, const char* am_test, TYPE am_testClassName)
- Declares a test and takes three parameters that organize the test tree (Parts -> Groups -> Tests)
FCF_TEST_BEFORE_DEFINE(const char* am_part, const char* am_group, const char* am_test, fcf::NTest::EFixtureLevel am_level)
FCF_TEST_BEFORE_DEFINE(const char* am_part, const char* am_group, const char* am_test, fcf::NTest::EFixtureLevel am_level, TYPE am_fixtureClassName)
- Starts the declaration of a test fixture. It defines the scope (Part, Group, or Test) and the execution level of the fixture.
FCF_TEST_AFTER_DEFINE(const char* am_part, const char* am_group, const char* am_test, fcf::NTest::EFixtureLevel am_level)
FCF_TEST_AFTER_DEFINE(const char* am_part, const char* am_group, const char* am_test, fcf::NTest::EFixtureLevel am_level, TYPE am_fixtureClassName)
- Ends the declaration of a test fixture. It defines the teardown logic that runs after the fixture's scope has ended.
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.
bool FCF_TEST_CHECK(bool am_expression, [mixed am_observedVariable...])
- A non-throwing assertion macro. It checks a logical expression and, if the check fails, adds the error to the test error list with detailed context, while allowing the test execution to continue.
FCF_TEST_THROW(CODE_BLOCK am_code, TYPE am_exception, [mixed am_observedVariable...])
- Asserts that a code block throws a specific exception. If no exception is thrown, or an unexpected exception type is caught, it generates a detailed error report and throws a std::runtime_error.
bool FCF_TEST_THROW_CHECK(CODE_BLOCK am_code, TYPE am_exception, [mixed am_observedVariable...])
- A non-throwing assertion macro. It checks if a code block throws a specific exception. If no exception is thrown, it logs an error and returns false without interrupting the test execution.
FCF_TEST_PART_ORDER(const char* am_part, int am_order)
- Registers a deterministic execution priority for a specific test part. Lower integer values indicate higher priority (run earlier).
FCF_TEST_GROUP_ORDER(const char* am_group, int am_order)
- Registers a deterministic execution priority for a specific test group. Lower integer values indicate higher priority (run earlier).
FCF_TEST_TEST_ORDER(const char* am_part, int am_test)
- Registers a deterministic execution priority for a specific test. Lower integer values indicate higher priority (run earlier).
- value = 1000000. Defines the default execution priority for a test part. Lower integer values indicate higher priority (run earlier).
Classes
- A lightweight structure representing a single unit test case, containing its hierarchical metadata and execution function pointer.
- A simple structure representing the hierarchical location of a test case within the framework (Part, Group, and Test name).
- A structure representing a setup or teardown operation that can be applied at various levels of the test hierarchy.
- This structure holds the configuration for running tests. It is populated automatically by the command line parser but can be used manually.
- A thread-safe central repository for all registered tests, fixtures, and execution metadata.
- A thread-safe singleton class that manages the global execution state of the test runner, including test results, execution duration, and custom user data.
- 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.
- A configurable logging utility providing multiple severity levels and customizable output formatting via static prefixes or functional callbacks
- A lightweight, type-erased smart pointer implementation providing reference-counted storage for arbitrary data types.
Functions
fcf::NTest::ECmdMode fcf::NTest::cmdRun(int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode, bool* a_errorPtr)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(fcf::NTest::Options& a_dstsrcOptions, int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(fcf::NTest::Options& a_dstsrcOptions, int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode, bool* a_errorPtr)
- 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)
void fcf::NTest::run(const fcf::NTest::Options& a_options, bool* a_errorPtr)
- Executes the selected tests based on the provided fcf::NTest::Options configuration. If an error occurs during test execution, the error condition is reported via the provided pointer, or an exception is thrown if the function is called without the a_errorPtr argument.
fcf::NTest::State& fcf::NTest::state()
- Provides access to the global singleton instance of the test state.
fcf::NTest::Storage& fcf::NTest::storage()
- Provides access to the global singleton instance of the central test storage.
fcf::NTest::Logger& fcf::NTest::logger()
- Provides global access to the singleton logger instance for configurable, multi-level diagnostic output with support for custom static and dynamic prefixes
fcf::NTest::Logger::Writer fcf::NTest::ftl(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for fatal-level log messages. This level is used for critical failures that require immediate attention.
fcf::NTest::Logger::Writer fcf::NTest::err(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for error-level log messages. This level is used to report significant issues that do not necessarily terminate the application
fcf::NTest::Logger::Writer fcf::NTest::wrn(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for warning-level log messages. This level is used for warnings that require immediate attention.
fcf::NTest::Logger::Writer fcf::NTest::att(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for attention-level log messages. This level is used for important message that require attention.
fcf::NTest::Logger::Writer fcf::NTest::log(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for default level log messages. This level is used for simple message that require attention.
fcf::NTest::Logger::Writer fcf::NTest::inf(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for info level log messages. This level is used for message with a secondary importance
fcf::NTest::Logger::Writer fcf::NTest::dbg(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for debug log messages. This logging level is used to output the debugging mesasge.
fcf::NTest::Logger::Writer fcf::NTest::trc(unsigned int a_messageCategory = fcf::NTest::LMC_USER_GROUP)
- Returns an fcf::NTest::Logger::Writer object for trace log messages. This logging level is used to extract tracing data.