About
maxon::UnitTestInterface provides an unified interface for any kind of unit test. Such an unit test should verify the correct functionality of every component of a program. Unit tests implemented this way are automatically executed when Cinema 4D starts and unit tests are enabled.
Implementation
Custom unit test are created by implementing a custom class based on maxon::UnitTestComponent. This custom class must implement maxon::UnitTestInterface::Run() which contains the unit test code.
The result of a test can be printed to the console using a standard format:
A (long running) unit test may be cancelled from the outside:
- Note
 - To measure time for speed tests one can use maxon::TimeValue.
 
 
{
 
public:
  {
    
    {
      const SimpleMaths baseTest(number);
 
      self.AddResult("GetNumber() test"_s, baseRes);
 
      
        return baseRes;
    }
 
    
    {
      SimpleMaths addTest(99);
      addTest.AddNumber(1);
 
      self.AddResult("AddNumber() test"_s, addTestRes);
    }
 
    
    {
      SimpleMaths subTest(100);
      subTest.SubstractNumber(1);
 
      self.AddResult("SubstractNumber() test"_s, subTestRes);
    }
 
  }
};
SFINAEHelper< Error, RESULT_TYPE >::type GetError() const
Definition: resultbase.h:1032
 
Definition: unittest.h:180
 
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:213
 
#define MAXON_SCOPE
Definition: apibase.h:2898
 
return OK
Definition: apibase.h:2747
 
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
 
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2199
 
  The result of this unit test will be printed to the console:
==========================================
@Running unit 
test 1 / 1: net.maxonexample.unittest.simplemaths
 
==========================================
Unittest 
"net.maxonexample.unittest.simplemaths" OK: GetNumber() 
test 
Duration: 0.5 ms
==========================================
@ScriptRef End
OK
Ok.
Definition: ge_prepass.h:0
 
#define test
Definition: graminit.h:53
 
Definition: animation_attributes.h:10
 
Registration
Different kinds of unit tests can be registered at these registries:
maxon::UnitTestClasses
- Contains pure functional tests that run in less than 2000 ms.
 
- Should use identifiers in the form of 
net.maxonexample.unittest.mytest. 
- Invoked with the command line argument 
g_runUnitTests. 
 
maxon::SpeedTestClasses
- Contains speed tests that run in 2000 ms or more.
 
- Should use identifiers in the form of 
net.maxonexample.speedtestclass.mytest. 
- Invoked with the command line argument 
g_runSpeedTests. 
 
maxon::LongRunTestClasses
- Contains functional tests that run in 2000 ms and more.
 
- Should use identifiers in the form of 
net.maxonexample.longruntestclass.mytest. 
- Invoked with the command line argument 
g_runLongRunTests. 
 
To run all unit tests set the command line argument to "*" like g_runUnitTests=*. To run a specific test one can define a filter like g_runUnitTests=*simplemaths*.
 
#define MAXON_COMPONENT_CLASS_REGISTER(C,...)
Definition: objectbase.h:2397
 
  
Further Reading