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>
Result<void> Run()
Bool res;
// 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");

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_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 ( UnitTestInterface  ,

◆ Run()

MAXON_METHOD Result<void> Run ( )

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

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.

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
[in]testNameA unique name within your test class. This is the identifier for later comparisons with previous builds.
[in]stateThe result of the test.

◆ 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.

[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 
MAXON_METHOD Result< void > Run()
Definition: objectbase.h:2036
return OK
Definition: apibase.h:2532
Definition: objectbase.h:2233
Definition: memoryallocationbase.h:66
maxon::Bool Bool
Definition: ge_sys_math.h:53