Base Framework
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
UnitTest Class Reference

#include <base/UnitTest.h>

Inherits ReferenceCountedObject.

Classes

class  _Here
 
class  _NotHere
 
class  AddDependency
 
class  HereMeta
 
class  Marker
 
class  Run
 
class  TestResult
 

Public Types

enum  { HERE_MARKER = 0x21564836, DEFAULT_PRIORITY = 0, DEFAULT_TIMEOUT = 15 * 60 * 1000 }
 
enum  Impact {
  PRIVACY, SECURITY, CRITICAL, IMPORTANT,
  NORMAL, LOW, IGNORE
}
 
enum  ResultEvent { FAILED, PASSED, PRINT }
 

Public Member Functions

void onException (const Exception *exception)
 
 UnitTest ()
 
void setName (const String &name)
 
void setDescription (const String &description)
 
void setSource (const String &source, unsigned int line=0)
 
void setType (const Type &type)
 
String getId () const
 
const StringgetName () const noexcept
 
const StringgetDescription () const noexcept
 
const StringgetSource () const noexcept
 
unsigned int getLine () const noexcept
 
const TypegetType () const noexcept
 
virtual bool getAllowConcurrentRun () const noexcept
 
virtual int getPriority () const noexcept
 
virtual bool isInDevelopment () const noexcept
 
virtual Impact getImpact () const noexcept
 
virtual String getOwner () const noexcept
 
virtual String getProject () const noexcept
 
virtual unsigned int getTimeout () const noexcept
 
virtual bool hasExternalDependency () const noexcept
 
virtual unsigned int getRepeats () const noexcept
 
virtual uint64 getLimitIO () const noexcept
 
virtual uint64 getLimitProcessingTime () const noexcept
 
virtual uint64 getLimitMemory () const noexcept
 
Reference< RungetLastRun ()
 
const Array< String > & getDependencies () const noexcept
 
void addDependency (const String &id)
 
String makeFolder ()
 
virtual void run ()
 
AnyValue getState (const String &id)
 
void setState (const String &id, const AnyValue &value)
 
Reference< RunrunImpl ()
 
String getJUnit () const
 
- Public Member Functions inherited from ReferenceCountedObject
 ReferenceCountedObject () noexcept
 
 ReferenceCountedObject (const ReferenceCountedObject &copy) noexcept
 
 ReferenceCountedObject (ReferenceCountedObject &&move) noexcept
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &copy) noexcept
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&move) noexcept
 
MemorySize getNumberOfReferences_INTERNAL () const noexcept
 
virtual bool useGarbageCollector () const noexcept
 
- Public Member Functions inherited from DynamicObject
 DynamicObject () noexcept
 
bool isValidObject () const noexcept
 
virtual ~DynamicObject () noexcept(false)
 
 _COM_AZURE_DEV__BASE__OVERRIDE_ALLOC ()
 

Public Attributes

const typedef _HereHere
 
const typedef _NotHereNotHere
 

Protected Member Functions

void onPrint (const String &what, unsigned int line=0)
 
void onPrintIssue (const String &what, unsigned int line=0)
 
void onPassed (const String &what, unsigned int line=0)
 
void onFailed (const String &what, unsigned int line=0)
 
void onAssert (bool passed, const String &what, unsigned int line=0)
 
void registerHere (const Here *here, const char *description)
 
void registerNotHere (const NotHere *here, const char *description)
 
void onHere (const Here *here)
 
void onNotHere (const NotHere *here)
 

Detailed Description

Unit test.

Member Enumeration Documentation

◆ Impact

Potential impact of test. Lower is worse.

◆ ResultEvent

A single result event.

Constructor & Destructor Documentation

◆ UnitTest()

UnitTest::UnitTest ( )

Initializes the test.

Member Function Documentation

◆ addDependency()

void UnitTest::addDependency ( const String id)
inline

Adds dependency.

◆ getAllowConcurrentRun()

virtual bool UnitTest::getAllowConcurrentRun ( ) const
inlinevirtualnoexcept

Use TEST_ALLOW_CONCURRENT to allow concurrent test runs.

◆ getDependencies()

const Array<String>& UnitTest::getDependencies ( ) const
inlinenoexcept

Returns dependencies.

◆ getDescription()

const String& UnitTest::getDescription ( ) const
inlinenoexcept

Returns the description of the test.

◆ getId()

String UnitTest::getId ( ) const

Returns the ID of the test (project/name).

◆ getImpact()

virtual Impact UnitTest::getImpact ( ) const
inlinevirtualnoexcept

Use TEST_IMPACT to set priority for test.

◆ getJUnit()

String UnitTest::getJUnit ( ) const

Returns the JUnit fragment.

◆ getLastRun()

Reference<Run> UnitTest::getLastRun ( )
inline

Returns the last run.

◆ getLimitIO()

virtual uint64 UnitTest::getLimitIO ( ) const
inlinevirtualnoexcept

Use TEST_LIMIT_IO to set IO limit.

◆ getLimitMemory()

virtual uint64 UnitTest::getLimitMemory ( ) const
inlinevirtualnoexcept

Use TEST_LIMIT_MEMORY to set processing time limit.

◆ getLimitProcessingTime()

virtual uint64 UnitTest::getLimitProcessingTime ( ) const
inlinevirtualnoexcept

Use TEST_LIMIT_TIME_MS to set processing time limit.

◆ getLine()

unsigned int UnitTest::getLine ( ) const
inlinenoexcept

Returns the source line of the test.

◆ getName()

const String& UnitTest::getName ( ) const
inlinenoexcept

Returns the name/id of the test.

◆ getOwner()

virtual String UnitTest::getOwner ( ) const
inlinevirtualnoexcept

Use TEST_OWNER to set owner for test.

◆ getPriority()

virtual int UnitTest::getPriority ( ) const
inlinevirtualnoexcept

Use TEST_PRIORITY to set priority for test.

◆ getProject()

virtual String UnitTest::getProject ( ) const
inlinevirtualnoexcept

Use TEST_PROJECT to set project for test.

◆ getRepeats()

virtual unsigned int UnitTest::getRepeats ( ) const
inlinevirtualnoexcept

Use TEST_REPEATS to set number of repeats.

◆ getSource()

const String& UnitTest::getSource ( ) const
inlinenoexcept

Returns the source of the test.

◆ getState()

AnyValue UnitTest::getState ( const String id)

Returns the global state. Allows tests to share state. But keep tests deterministic.

◆ getTimeout()

virtual unsigned int UnitTest::getTimeout ( ) const
inlinevirtualnoexcept

Use TEST_TIMEOUT_MS to set priority for test.

◆ getType()

const Type& UnitTest::getType ( ) const
inlinenoexcept

Returns the type (from class) of the test.

◆ hasExternalDependency()

virtual bool UnitTest::hasExternalDependency ( ) const
inlinevirtualnoexcept

Use TEST_EXTERNAL to tag test as having external dependencies.

◆ isInDevelopment()

virtual bool UnitTest::isInDevelopment ( ) const
inlinevirtualnoexcept

Use TEST_IN_DEVELOPMENT to tag test as being in development.

◆ makeFolder()

String UnitTest::makeFolder ( )

Creates a folder for the test and returns the path.

◆ onAssert()

void UnitTest::onAssert ( bool  passed,
const String what,
unsigned int  line = 0 
)
protected

Called when subtest failed.

◆ onException()

void UnitTest::onException ( const Exception exception)

Called on exception.

◆ onFailed()

void UnitTest::onFailed ( const String what,
unsigned int  line = 0 
)
protected

Called when subtest failed.

◆ onHere()

void UnitTest::onHere ( const Here *  here)
protected

Called when here point is reached.

◆ onNotHere()

void UnitTest::onNotHere ( const NotHere *  here)
protected

Called when nothere point is reached but shouldn't be reached.

◆ onPassed()

void UnitTest::onPassed ( const String what,
unsigned int  line = 0 
)
protected

Called when subtest passed.

◆ onPrint()

void UnitTest::onPrint ( const String what,
unsigned int  line = 0 
)
protected

Called on explicit print request.

◆ onPrintIssue()

void UnitTest::onPrintIssue ( const String what,
unsigned int  line = 0 
)
protected

Called on explicit print request.

◆ registerHere()

void UnitTest::registerHere ( const Here *  here,
const char *  description 
)
protected

Called when here point is declared.

◆ registerNotHere()

void UnitTest::registerNotHere ( const NotHere *  here,
const char *  description 
)
protected

Called when not-here point is declared.

◆ run()

virtual void UnitTest::run ( )
virtual

Runs the test.

◆ runImpl()

Reference<Run> UnitTest::runImpl ( )

Internal run.

◆ setDescription()

void UnitTest::setDescription ( const String description)

Sets the description of the test.

◆ setName()

void UnitTest::setName ( const String name)

Sets the name/id of the test.

◆ setSource()

void UnitTest::setSource ( const String source,
unsigned int  line = 0 
)

Sets the source file of the test.

◆ setState()

void UnitTest::setState ( const String id,
const AnyValue value 
)

Sets the global state. Allows tests to share state. But keep tests deterministic.

◆ setType()

void UnitTest::setType ( const Type type)

Sets the type (from class) of the test.