UnitTestInterface Class Reference

#include <unittest.h>

Inheritance diagram for UnitTestInterface:

Detailed Description

Class for Unit tests. All available interfaces and implementations should get a unit test to verify the correct function of the interface. A unit test should check the positive and negative return values. E.g. also if giving wrong arguments to functions return the expected error code. There are 3 different categories of tests right now. They can be registered with MAXON_COMPONENT_CLASS_REGISTER.

  • Pure functional unit tests registered using the UnitTestClasses identifier. This kind of test should pass within seconds and test only if all functions operates correctly. Those unit tests will be executed and checked for every build on the build server.
  • Speed tests registered using the SpeedTestClasses identifier. This kind of test should pass within seconds.
  • Long run Tests registered using the LongRunTestClasses identifier.

Here is an example how this class should be used:

class UnitTestExample : public UnitTestComponent<UnitTestExample>
{
public:
Result<void> Run()
{
// Do some operations here.
res = (5 == 5);
// Add the result to the database.
self.AddResult("Test 1"_s, res ? OK : UnitTestError(MAXON_SOURCE_LOCATION, "5 == 5"_s));
// Do more Tests.
return OK;
}
};
MAXON_COMPONENT_CLASS_REGISTER(UnitTestExample, UnitTestClasses, "net.maxon.unittest.example");
MAXON_METHOD Result< void > Run()
Py_UCS4 * res
Definition: unicodeobject.h:1113
maxon::Bool Bool
Definition: ge_sys_math.h:55
return OK
Definition: apibase.h:2690
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
#define MAXON_COMPONENT_CLASS_REGISTER(C,...)
Definition: objectbase.h:2409

Public Member Functions

MAXON_METHOD Result< void > Run ()
 
MAXON_METHOD Bool IsCancelled () const
 
MAXON_METHOD void Cancel ()
 
MAXON_METHOD void AddResult (const String &testName, Result< void > state)
 
MAXON_FUNCTION void AddResultBool (const String &testName, Bool state)
 
MAXON_METHOD void AddTimingResult (const String &testName, Result< void > state, TimeValue duration)
 
MAXON_METHOD Bool ReInitializeBuildId (const String &buildId, const UniversalDateTime &dateTime)
 

Private Member Functions

 MAXON_INTERFACE (UnitTestInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.unittest")
 

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( UnitTestInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.unittest"   
)
private

◆ Run()

MAXON_METHOD Result<void> Run ( )

This functions needs to be overridden with the implementation of the test code (see example).

Returns
OK on success. The result has no effect on other unit tests. If an error is returned it will be output (and added to the SQL database if enabled).

◆ IsCancelled()

MAXON_METHOD Bool IsCancelled ( ) const

Checks if the Test has been cancelled from outside.

Returns
In case of true the test should exit immediately.

◆ Cancel()

MAXON_METHOD void Cancel ( )

Cancel all UnitTestClasses.

◆ AddResult()

MAXON_METHOD void AddResult ( const String testName,
Result< void >  state 
)

Outputs the result to the console in a standard format. This format can be analyzed by tools. The output may be added to an SQL database. The example above prints these lines:

Running unit test 9/16: net.maxon.unittest.example
Unittest "net.maxon.unittest.example" OK: Test1
#define test
Definition: graminit.h:53
Parameters
[in]testNameA unique name within your test class. This is the identifier for later comparisons with previous builds.
[in]stateThe result of the test.

◆ AddResultBool()

MAXON_FUNCTION void AddResultBool ( const String testName,
Bool  state 
)

Outputs the result to the console in a standard format. This is similar to AddResult, but you have to provide just a Bool value where false indicates a failure.

Parameters
[in]testNameA unique name within your test class. This is the identifier for later comparisons with previous builds.
[in]stateThe result of the test: true means success, false means failure.

◆ AddTimingResult()

MAXON_METHOD void AddTimingResult ( const String testName,
Result< void >  state,
TimeValue  duration 
)

Outputs the result with timing to the console in a standard format. Same AddResult() but with timing added.

Parameters
[in]testNameA unique name within your test class. This is the identifier for later comparisons with previous builds.
[in]stateThe result of the test.
[in]durationDuration of the test.

◆ ReInitializeBuildId()

MAXON_METHOD Bool ReInitializeBuildId ( const String buildId,
const UniversalDateTime dateTime 
)