micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::test_suite Class Reference

Represents a named group of test cases that self-register to the runner. More...

#include <micro-os-plus/micro-test-plus.h>

Inheritance diagram for micro_os_plus::micro_test_plus::test_suite:

Public Member Functions

template<typename Callable_T, typename... Args_T>
 test_suite (const char *name, Callable_T &&callable, Args_T &&... arguments)
 Class template constructor for test_suite.
 test_suite (const test_suite &)=delete
 Deleted copy constructor to prevent copying.
 test_suite (test_suite &&)=delete
 Deleted move constructor to prevent moving.
virtual ~test_suite () override
 Virtual destructor for the test_suite class.
void begin_test_case (const char *name)
 Marks the beginning of a named test case.
void begin_test_suite (void)
 Begins the execution of the test suite.
void end_test_case (void)
 Marks the end of a test case.
void end_test_suite (void)
 Marks the end of the test suite.
constexpr int failed_checks (void)
 Gets the number of test conditions that failed.
void increment_failed (void)
 Increments the count of failed test conditions.
void increment_successful (void)
 Increments the count of passed test conditions.
constexpr const char * name (void)
 Gets the suite name.
test_suiteoperator= (const test_suite &)=delete
 Deleted copy assignment operator to prevent copying.
test_suiteoperator= (test_suite &&)=delete
 Deleted move assignment operator to prevent moving.
virtual void run (void) override
 Runs the sequence of test cases in the suite by invoking the stored callable.
constexpr int successful_checks (void)
 Gets the number of conditions that passed.
constexpr int test_cases (void)
 Gets the number of test cases.
constexpr bool unused (void)
 Checks if the test suite was not used.
constexpr bool was_successful (void)
 Gets the test suite result.

Public Attributes

struct { 
   int   failed_checks 
 Number of failed checks in the current test case. More...
   int   successful_checks 
 Number of successful checks in the current test case. More...
current_test_case
 Structure holding the current test case's check counters.
bool process_deferred_begin = true
 Indicates whether to process deferred begin for test cases.

Protected Attributes

std::function< void(void)> callable_
 Callable object representing the test suite's execution logic.
int failed_checks_ = 0
 Count of test conditions that failed.
const char * name_
 The test suite name.
int successful_checks_ = 0
 Count of test conditions that passed.
const char * test_case_name_
 The current test case name.
int test_cases_ = 0
 Count of test cases in the test suite.

Detailed Description

The test_suite class extends test_suite_base and enables the registration and execution of callable objects (such as lambdas or function pointers) as test suites. Upon construction, each test suite automatically registers itself with the test runner, facilitating automated test discovery and execution across different components and folders of a project.

This class template provides a flexible mechanism for grouping related test cases and managing their execution within the µTest++ framework. It ensures that test suites are non-copyable and non-movable, maintaining unique ownership and consistent state.

All members and methods are defined within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

Definition at line 371 of file test-suite.h.

Constructor & Destructor Documentation

◆ test_suite() [1/3]

template<typename Callable_T, typename... Args_T>
micro_os_plus::micro_test_plus::test_suite::test_suite ( const char * name,
Callable_T && callable,
Args_T &&... arguments )
Template Parameters
Callable_TThe type of a callable object.
Args_TThe types of the callable arguments.
Parameters
[in]nameThe test case name or description, used in reports.
[in]callableA generic callable object, usually a lambda, invoked to perform the test.
[in]argumentsA possibly empty list of arguments to be passed to the callable.

The rule of five is enforced to prevent accidental copying or moving.

This constructor initialises a test suite by binding the provided callable and its arguments, and registers the suite with the test runner.

The callable is bound using std::bind, allowing for flexible test suite definitions with arbitrary arguments. Upon construction, the test suite is automatically registered with the global runner for execution.

Definition at line 88 of file test-suite-inlines.h.

91 callable_{ std::bind (callable, arguments...) }
92 {
93#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
94 printf ("%s\n", __PRETTY_FUNCTION__);
95#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
96
98 }
void register_test_suite(test_suite_base *suite)
Registers a test suite with the runner.
test_suite_base(const char *name)
Constructs a test suite.
constexpr const char * name(void)
Gets the suite name.
Definition test-suite.h:178
std::function< void(void)> callable_
Callable object representing the test suite's execution logic.
Definition test-suite.h:438
test_runner runner
Global instance of test_runner.

References micro_os_plus::micro_test_plus::test_suite_base::test_suite_base(), callable_, micro_os_plus::micro_test_plus::test_suite_base::name(), and micro_os_plus::micro_test_plus::runner.

Referenced by test_suite(), test_suite(), operator=(), and operator=().

◆ test_suite() [2/3]

micro_os_plus::micro_test_plus::test_suite::test_suite ( const test_suite & )
delete

References test_suite().

◆ test_suite() [3/3]

micro_os_plus::micro_test_plus::test_suite::test_suite ( test_suite && )
delete

References test_suite().

◆ ~test_suite()

micro_os_plus::micro_test_plus::test_suite::~test_suite ( )
overridevirtual

The destructor releases any resources associated with the test_suite instance. If tracing is enabled, it outputs the function signature for diagnostic purposes. This ensures that the test suite is properly cleaned up after execution, supporting robust and reliable test management across all files and folders within the µTest++ framework.

Definition at line 241 of file test-suite.cpp.

242 {
243#if defined(MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS)
244 printf ("%s\n", __PRETTY_FUNCTION__);
245#endif // MICRO_OS_PLUS_TRACE_MICRO_TEST_PLUS
246 }

Member Function Documentation

◆ begin_test_case()

void micro_os_plus::micro_test_plus::test_suite_base::begin_test_case ( const char * name)
inherited
Parameters
[in]nameThe test case name.
Returns
Nothing.

This method marks the beginning of a test case within the suite. If the start of the suite was deferred, it ensures the suite is properly begun before proceeding. The method sets the current test case name, increments the total number of test cases, resets the current test case statistics, and notifies the test reporter to begin the test case. This approach guarantees that each test case is clearly identified, accurately tracked, and properly reported across all test cases and folders.

Definition at line 159 of file test-suite.cpp.

160 {
162 {
164 }
165
167 ++test_cases_;
168
170
172 }
void begin_test_case(const char *name)
Mark the beginning of a test case.
int test_cases_
Count of test cases in the test suite.
Definition test-suite.h:318
bool process_deferred_begin
Indicates whether to process deferred begin for test cases.
Definition test-suite.h:324
struct micro_os_plus::micro_test_plus::test_suite_base::@025050103341037176303320301005170305141235061044 current_test_case
Structure holding the current test case's check counters.
void begin_test_suite(void)
Begins the execution of the test suite.
const char * test_case_name_
The current test case name.
Definition test-suite.h:303
test_reporter reporter
Global instance of test_reporter.

References begin_test_suite(), current_test_case, name(), process_deferred_begin, micro_os_plus::micro_test_plus::reporter, test_case_name_, and test_cases_.

◆ begin_test_suite()

void micro_os_plus::micro_test_plus::test_suite_base::begin_test_suite ( void )
inherited
Parameters
None.
Returns
Nothing.

This method marks the beginning of a test suite's execution. It resets the deferred begin flag and notifies the test reporter to start the suite, passing the suite's name. This ensures that test suite output is clearly delineated and properly initialised, supporting organised and readable reporting across all test cases and folders.

Definition at line 122 of file test-suite.cpp.

123 {
125
127 }
void begin_test_suite(const char *name)
Mark the beginning of a test suite.
const char * name_
The test suite name.
Definition test-suite.h:298

References name_, process_deferred_begin, and micro_os_plus::micro_test_plus::reporter.

Referenced by begin_test_case(), and end_test_suite().

◆ end_test_case()

void micro_os_plus::micro_test_plus::test_suite_base::end_test_case ( void )
inherited
Parameters
None.
Returns
Nothing.

This method marks the end of a test case within the suite. It notifies the test reporter to conclude the test case, passing the current test case name. This ensures that the results of the test case are accurately finalised and clearly reported, supporting organised and reliable test management across all test cases and folders.

Definition at line 183 of file test-suite.cpp.

184 {
186 }
void end_test_case(const char *name)
Mark the end of a test case.

References micro_os_plus::micro_test_plus::reporter, and test_case_name_.

◆ end_test_suite()

void micro_os_plus::micro_test_plus::test_suite_base::end_test_suite ( void )
inherited
Parameters
None.
Returns
Nothing.

This method marks the end of a test suite's execution. If the suite's start was deferred, it ensures the suite is properly begun before finalising. The method then notifies the test reporter to conclude the suite, passing a reference to the suite instance. This guarantees that all results are accurately summarised and reported, supporting clear and organised test management across all test cases and folders.

Definition at line 139 of file test-suite.cpp.

140 {
142 {
144 }
145 reporter.end_test_suite (*this);
146 }
void end_test_suite(test_suite_base &suite)
Mark the end of a test suite.

References begin_test_suite(), process_deferred_begin, and micro_os_plus::micro_test_plus::reporter.

◆ failed_checks()

int micro_os_plus::micro_test_plus::test_suite_base::failed_checks ( void )
inlinenodiscardconstexprinherited
Parameters
None.
Returns
An integer with the number of checks that failed.

Definition at line 226 of file test-suite.h.

227 {
228 return failed_checks_;
229 }
int failed_checks_
Count of test conditions that failed.
Definition test-suite.h:313

References failed_checks_.

◆ increment_failed()

void micro_os_plus::micro_test_plus::test_suite_base::increment_failed ( void )
inherited
Parameters
None.
Returns
Nothing.

This method increments the count of failed checks for the test suite and the current test case. It ensures that each failing assertion is accurately recorded, supporting precise tracking and reporting of test outcomes across all test cases and folders.

Definition at line 210 of file test-suite.cpp.

211 {
213 ++current_test_case.failed_checks;
214 }

References current_test_case, and failed_checks_.

◆ increment_successful()

void micro_os_plus::micro_test_plus::test_suite_base::increment_successful ( void )
inherited
Parameters
None.
Returns
Nothing.

This method increments the count of successful checks for the test suite and the current test case. It ensures that each passing assertion is accurately recorded, supporting precise tracking and reporting of test outcomes across all test cases and folders.

Definition at line 196 of file test-suite.cpp.

197 {
199 ++current_test_case.successful_checks;
200 }
int successful_checks_
Count of test conditions that passed.
Definition test-suite.h:308

References current_test_case, and successful_checks_.

◆ name()

const char * micro_os_plus::micro_test_plus::test_suite_base::name ( void )
inlinenodiscardconstexprinherited
Parameters
None.
Returns
A pointer to the null-terminated test suite name.

Definition at line 178 of file test-suite.h.

179 {
180 return name_;
181 }

References name_.

Referenced by micro_os_plus::micro_test_plus::test_suite::test_suite(), test_suite_base(), begin_test_case(), micro_os_plus::micro_test_plus::test_reporter::end_test_suite(), and operator=().

◆ operator=() [1/2]

test_suite & micro_os_plus::micro_test_plus::test_suite::operator= ( const test_suite & )
delete

References test_suite().

◆ operator=() [2/2]

test_suite & micro_os_plus::micro_test_plus::test_suite::operator= ( test_suite && )
delete

References test_suite().

◆ run()

void micro_os_plus::micro_test_plus::test_suite::run ( void )
overridevirtual
Parameters
None.
Returns
Nothing.

This method executes the test suite by invoking the stored callable object associated with the suite. It ensures that all test cases registered within the suite are executed in sequence, supporting comprehensive and structured testing across all files and folders within the µTest++ framework.

Reimplemented from micro_os_plus::micro_test_plus::test_suite_base.

Definition at line 227 of file test-suite.cpp.

228 {
229 // Run the test suite function prepared with std::bin();
230 callable_ ();
231 }

References callable_.

◆ successful_checks()

int micro_os_plus::micro_test_plus::test_suite_base::successful_checks ( void )
inlinenodiscardconstexprinherited
Parameters
None.
Returns
An integer with the number of checks that passed.

Definition at line 213 of file test-suite.h.

214 {
215 return successful_checks_;
216 }

References successful_checks_.

◆ test_cases()

int micro_os_plus::micro_test_plus::test_suite_base::test_cases ( void )
inlinenodiscardconstexprinherited
Parameters
None.
Returns
An integer with the number of test cases.

Definition at line 239 of file test-suite.h.

240 {
241 return test_cases_;
242 }

References test_cases_.

Referenced by micro_os_plus::micro_test_plus::test_reporter::end_test_suite().

◆ unused()

bool micro_os_plus::micro_test_plus::test_suite_base::unused ( void )
inlinenodiscardconstexprinherited
Parameters
None.
Returns
True if the test suite is not used.

Definition at line 288 of file test-suite.h.

289 {
290 return (failed_checks_ == 0 && successful_checks_ == 0
291 && test_cases_ == 0);
292 }

References failed_checks_, successful_checks_, and test_cases_.

◆ was_successful()

bool micro_os_plus::micro_test_plus::test_suite_base::was_successful ( void )
inlinenodiscardconstexprinherited
Parameters
None.
Returns
True if the test suite was successful.

Definition at line 274 of file test-suite.h.

275 {
276 // Also fail if none passed.
277 return (failed_checks_ == 0 && successful_checks_ != 0);
278 }

References failed_checks_, and successful_checks_.

Member Data Documentation

◆ callable_

std::function<void (void)> micro_os_plus::micro_test_plus::test_suite::callable_
protected

Definition at line 438 of file test-suite.h.

Referenced by test_suite(), and run().

◆ [struct]

struct { ... } micro_os_plus::micro_test_plus::test_suite_base::current_test_case

Tracks the number of successful and failed checks for the currently running test case.

Referenced by begin_test_case(), increment_failed(), and increment_successful().

◆ failed_checks

int micro_os_plus::micro_test_plus::test_suite_base::failed_checks ( void )
inherited

◆ failed_checks_

int micro_os_plus::micro_test_plus::test_suite_base::failed_checks_ = 0
protectedinherited

Definition at line 313 of file test-suite.h.

Referenced by failed_checks(), increment_failed(), unused(), and was_successful().

◆ name_

const char* micro_os_plus::micro_test_plus::test_suite_base::name_
protectedinherited

Definition at line 298 of file test-suite.h.

Referenced by test_suite_base(), begin_test_suite(), and name().

◆ process_deferred_begin

bool micro_os_plus::micro_test_plus::test_suite_base::process_deferred_begin = true
inherited

Definition at line 324 of file test-suite.h.

Referenced by begin_test_case(), begin_test_suite(), and end_test_suite().

◆ successful_checks

int micro_os_plus::micro_test_plus::test_suite_base::successful_checks ( void )
inherited

◆ successful_checks_

int micro_os_plus::micro_test_plus::test_suite_base::successful_checks_ = 0
protectedinherited

Definition at line 308 of file test-suite.h.

Referenced by increment_successful(), successful_checks(), unused(), and was_successful().

◆ test_case_name_

const char* micro_os_plus::micro_test_plus::test_suite_base::test_case_name_
protectedinherited

Definition at line 303 of file test-suite.h.

Referenced by begin_test_case(), and end_test_case().

◆ test_cases_

int micro_os_plus::micro_test_plus::test_suite_base::test_cases_ = 0
protectedinherited

Definition at line 318 of file test-suite.h.

Referenced by begin_test_case(), test_cases(), and unused().


The documentation for this class was generated from the following files: