Free Electron
Public Member Functions | Private Attributes | List of all members
fe::UnitTest Class Reference

Counts success and failures in a style similar to assertions. More...

#include <UnitTest.h>

Public Member Functions

virtual void operator() (bool success, const char *label="")
 Checks the "assertion" and log a message if it fails. More...
 
int failures (void)
 Return the number of failures so far. More...
 
int track (int expected)
 Compare the number of tests run to a reference. More...
 

Private Attributes

int m_successes
 
int m_failures
 
int m_attempts
 

Detailed Description

Counts success and failures in a style similar to assertions.

Instantiating the object starts unit testing for the scope.

Upon destruction, a report is sent to the global logger.

The block contains any number of tests.

By convention, a stand-alone unit test executable should return the number of failures and the exit status.

main()
{
fe::UnitTest unitTest;
unitTest(TRUE,"TRUE is non-zero");
unitTest.track(1);
return unitTest.failures();
}

For convenience a set of macros is provided:

main()
{
UNIT_START();
UNIT_TEST(TRUE);
UNIT_TRACK(1);
UNIT_RETURN();
}

Member Function Documentation

◆ failures()

int fe::UnitTest::failures ( void  )
inline

Return the number of failures so far.

◆ operator()()

virtual void fe::UnitTest::operator() ( bool  success,
const char *  label = "" 
)
inlinevirtual

Checks the "assertion" and log a message if it fails.

◆ track()

int fe::UnitTest::track ( int  expected)
inline

Compare the number of tests run to a reference.

Returns true if the numbers matched.


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