AUnit  0.5.0
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
aunit::Test Class Referenceabstract

Base class of all test cases. More...

#include <Test.h>

Inheritance diagram for aunit::Test:
Inheritance graph
[legend]

Public Member Functions

 Test ()
 Empty constructor. More...
 
virtual void setup ()
 Optional method that performs any initialization. More...
 
virtual void teardown ()
 Optional method that performs any clean up after the test ends for any reasons, either passing or otherwise. More...
 
virtual void loop ()=0
 The user-provided test case function. More...
 
void resolve ()
 Print out the summary of the current test. More...
 
const internal::FCStringgetName ()
 Get the name of the test. More...
 
uint8_t getLifeCycle ()
 Get the life cycle state of the test. More...
 
void setLifeCycle (uint8_t state)
 
uint8_t getStatus ()
 Get the status of the test. More...
 
void setStatus (uint8_t status)
 Set the status of the test. More...
 
void setPassOrFail (bool ok)
 Set the status to Passed or Failed depending on ok. More...
 
Test ** getNext ()
 Return the next pointer as a pointer to the pointer, similar to getRoot(). More...
 
bool isDone ()
 Return true if test has been asserted. More...
 
bool isNotDone ()
 Return true if test is not has been asserted. More...
 
bool isPassed ()
 Return true if test is passed. More...
 
bool isNotPassed ()
 Return true if test is not passed. More...
 
bool isFailed ()
 Return true if test is failed. More...
 
bool isNotFailed ()
 Return true if test is not failed. More...
 
bool isSkipped ()
 Return true if test is skipped. More...
 
bool isNotSkipped ()
 Return true if test is not skipped. More...
 
bool isExpired ()
 Return true if test is expired. More...
 
bool isNotExpired ()
 Return true if test is not expired. More...
 
void skip ()
 Mark the test as skipped. More...
 
void expire ()
 Mark the test as expired (i.e. More...
 
void enableVerbosity (uint8_t verbosity)
 Enable the given verbosity of the current test. More...
 
void disableVerbosity (uint8_t verbosity)
 Disable the given verbosity of the current test. More...
 

Static Public Member Functions

static Test ** getRoot ()
 Get the pointer to the root pointer. More...
 

Static Public Attributes

static const uint8_t kLifeCycleNew = 0
 Test is new, needs to be setup. More...
 
static const uint8_t kLifeCycleExcluded = 1
 Test is Excluded by an exclude() method. More...
 
static const uint8_t kLifeCycleSetup = 2
 Test has been set up by calling setup() and ready to execute the test code. More...
 
static const uint8_t kLifeCycleAsserted = 3
 Test is asserted (using pass(), fail(), expired() or skipped()) and the getStatus() has been determined. More...
 
static const uint8_t kLifeCycleFinished = 4
 The test has completed its life cycle. More...
 
static const uint8_t kStatusUnknown = 0
 Test status is unknown. More...
 
static const uint8_t kStatusPassed = 1
 Test has passed, or pass() was called. More...
 
static const uint8_t kStatusFailed = 2
 Test has failed, or fail() was called. More...
 
static const uint8_t kStatusSkipped = 3
 Test is skipped through the exclude() method or skip() was called. More...
 
static const uint8_t kStatusExpired = 4
 Test has timed out, or expire() called. More...
 

Protected Member Functions

void fail ()
 Mark the test as failed. More...
 
void pass ()
 Mark the test as passed. More...
 
void init (const char *name)
 
void init (const __FlashStringHelper *name)
 
bool isVerbosity (uint8_t verbosity)
 Determine if any of the given verbosity is enabled. More...
 
uint8_t getVerbosity ()
 Get the verbosity. More...
 

Detailed Description

Base class of all test cases.

The test() and testing() macros define subclasses of Test or TestOnce (respectively), and allow the code following the macros in '{}' to become the body of the loop() and once() methods of the two classes (respectively).

Definition at line 43 of file Test.h.

Constructor & Destructor Documentation

◆ Test()

aunit::Test::Test ( )

Empty constructor.

The name will be set later.

Definition at line 41 of file Test.cpp.

Member Function Documentation

◆ disableVerbosity()

void aunit::Test::disableVerbosity ( uint8_t  verbosity)
inline

Disable the given verbosity of the current test.

Definition at line 235 of file Test.h.

◆ enableVerbosity()

void aunit::Test::enableVerbosity ( uint8_t  verbosity)
inline

Enable the given verbosity of the current test.

Definition at line 232 of file Test.h.

◆ expire()

void aunit::Test::expire ( )
inline

Mark the test as expired (i.e.

timed out).

Definition at line 229 of file Test.h.

◆ fail()

void aunit::Test::fail ( )
inlineprotected

Mark the test as failed.

Definition at line 239 of file Test.h.

◆ getLifeCycle()

uint8_t aunit::Test::getLifeCycle ( )
inline

Get the life cycle state of the test.

Definition at line 161 of file Test.h.

◆ getName()

const internal::FCString& aunit::Test::getName ( )
inline

Get the name of the test.

Definition at line 158 of file Test.h.

◆ getNext()

Test** aunit::Test::getNext ( )
inline

Return the next pointer as a pointer to the pointer, similar to getRoot().

This makes it much easier to manipulate a singly-linked list. Also makes setNext() method unnecessary.

Definition at line 188 of file Test.h.

◆ getRoot()

Test ** aunit::Test::getRoot ( )
static

Get the pointer to the root pointer.

Implemented as a function static so fixes the C++ static initialization problem making it safe to use this in other static contexts.

Definition at line 36 of file Test.cpp.

◆ getStatus()

uint8_t aunit::Test::getStatus ( )
inline

Get the status of the test.

Definition at line 166 of file Test.h.

◆ getVerbosity()

uint8_t aunit::Test::getVerbosity ( )
inlineprotected

Get the verbosity.

Definition at line 264 of file Test.h.

◆ isDone()

bool aunit::Test::isDone ( )
inline

Return true if test has been asserted.

Note that this is different than the internal LifeCycleFinished state. The name isDone() is a carry-over from ArduinoUnit and might have been named isAsserted() if this library had been built from scratch.

Definition at line 196 of file Test.h.

◆ isExpired()

bool aunit::Test::isExpired ( )
inline

Return true if test is expired.

Definition at line 220 of file Test.h.

◆ isFailed()

bool aunit::Test::isFailed ( )
inline

Return true if test is failed.

Definition at line 208 of file Test.h.

◆ isNotDone()

bool aunit::Test::isNotDone ( )
inline

Return true if test is not has been asserted.

Definition at line 199 of file Test.h.

◆ isNotExpired()

bool aunit::Test::isNotExpired ( )
inline

Return true if test is not expired.

Definition at line 223 of file Test.h.

◆ isNotFailed()

bool aunit::Test::isNotFailed ( )
inline

Return true if test is not failed.

Definition at line 211 of file Test.h.

◆ isNotPassed()

bool aunit::Test::isNotPassed ( )
inline

Return true if test is not passed.

Definition at line 205 of file Test.h.

◆ isNotSkipped()

bool aunit::Test::isNotSkipped ( )
inline

Return true if test is not skipped.

Definition at line 217 of file Test.h.

◆ isPassed()

bool aunit::Test::isPassed ( )
inline

Return true if test is passed.

Definition at line 202 of file Test.h.

◆ isSkipped()

bool aunit::Test::isSkipped ( )
inline

Return true if test is skipped.

Definition at line 214 of file Test.h.

◆ isVerbosity()

bool aunit::Test::isVerbosity ( uint8_t  verbosity)
inlineprotected

Determine if any of the given verbosity is enabled.

Definition at line 261 of file Test.h.

◆ loop()

virtual void aunit::Test::loop ( )
pure virtual

The user-provided test case function.

EEach call to Test::run() makes one call to this loop() method. The assertXxx() macros, as well as pass(), fail() and skip() functions can be called in here.

Implemented in aunit::TestOnce, and aunit::TestAgain.

◆ pass()

void aunit::Test::pass ( )
inlineprotected

Mark the test as passed.

Definition at line 242 of file Test.h.

◆ resolve()

void aunit::Test::resolve ( )

Print out the summary of the current test.

Definition at line 73 of file Test.cpp.

◆ setPassOrFail()

void aunit::Test::setPassOrFail ( bool  ok)

Set the status to Passed or Failed depending on ok.

Definition at line 50 of file Test.cpp.

◆ setStatus()

void aunit::Test::setStatus ( uint8_t  status)
inline

Set the status of the test.

All changes to getStatus() should happen through this method because it also changes the getLifeCycle() of the test.

Definition at line 173 of file Test.h.

◆ setup()

virtual void aunit::Test::setup ( )
inlinevirtual

Optional method that performs any initialization.

The assertXxx() macros, as well as pass(), fail() and skip() functions can be called in here. Subclasses that override this should call the parent's setup() method in the first line so that the setup() methods in the inheritance tree are properly chained.

Definition at line 136 of file Test.h.

◆ skip()

void aunit::Test::skip ( )
inline

Mark the test as skipped.

Definition at line 226 of file Test.h.

◆ teardown()

virtual void aunit::Test::teardown ( )
inlinevirtual

Optional method that performs any clean up after the test ends for any reasons, either passing or otherwise.

Subclasses that override this should call the parent's teardown() method in the last line before returning, so that the teardown() methods in the inheritance tree are properly chained.

Definition at line 145 of file Test.h.

Member Data Documentation

◆ kLifeCycleAsserted

const uint8_t aunit::Test::kLifeCycleAsserted = 3
static

Test is asserted (using pass(), fail(), expired() or skipped()) and the getStatus() has been determined.

The teardown() method should be called.

Definition at line 80 of file Test.h.

◆ kLifeCycleExcluded

const uint8_t aunit::Test::kLifeCycleExcluded = 1
static

Test is Excluded by an exclude() method.

The setup() and teardown() methods are bypassed and the test goes directly to kLifeCycleFinished. For reporting purposes, an excluded test is counted as a "skipped" test. The include() method puts the test back into the kLifeCycleNew state.

Definition at line 65 of file Test.h.

◆ kLifeCycleFinished

const uint8_t aunit::Test::kLifeCycleFinished = 4
static

The test has completed its life cycle.

It should be resolved using resolve() and removed from the linked list. Note that this is different than isDone() (i.e. kStatusDone) which indicates that an assertion about the test has been made.

Definition at line 88 of file Test.h.

◆ kLifeCycleNew

const uint8_t aunit::Test::kLifeCycleNew = 0
static

Test is new, needs to be setup.

Definition at line 57 of file Test.h.

◆ kLifeCycleSetup

const uint8_t aunit::Test::kLifeCycleSetup = 2
static

Test has been set up by calling setup() and ready to execute the test code.

TestOnce tests (i.e. test() or testF()) should be in Setup state only for a single iteration. TestAgain tests (i.e. testing() or testingF()) will stay in Setup state until explicitly moved to a different state by the testing code (or the test times out).

Definition at line 74 of file Test.h.

◆ kStatusExpired

const uint8_t aunit::Test::kStatusExpired = 4
static

Test has timed out, or expire() called.

Definition at line 108 of file Test.h.

◆ kStatusFailed

const uint8_t aunit::Test::kStatusFailed = 2
static

Test has failed, or fail() was called.

Definition at line 102 of file Test.h.

◆ kStatusPassed

const uint8_t aunit::Test::kStatusPassed = 1
static

Test has passed, or pass() was called.

Definition at line 99 of file Test.h.

◆ kStatusSkipped

const uint8_t aunit::Test::kStatusSkipped = 3
static

Test is skipped through the exclude() method or skip() was called.

Definition at line 105 of file Test.h.

◆ kStatusUnknown

const uint8_t aunit::Test::kStatusUnknown = 0
static

Test status is unknown.

Definition at line 96 of file Test.h.


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