Jameo Core Library
Loading...
Searching...
No Matches
Classes | Variables
Test

A collection of classes to provide unit tests. More...

Classes

class  jm::Test
 This base class represents a test object. It is used to implement unit tests for any code. Typically a set of tests is collected in one derived test class. More...
 
class  jm::TestVector
 A TestVector is a collection of several tests and will execute them all and return the number of errors on execution. More...
 

Variables

size_t jm::gErrorCount
 global error count during single test run.
 
size_t jm::gTestCount
 global test count during single test run.
 
size_t jm::gTotalErrorCount
 global error count over all done tests.
 
size_t jm::gTotalTestCount
 global test count overall done tests.
 

Detailed Description

A collection of classes to provide unit tests.

Jameo Core library provides simple ways to perform unit testing. The following example code shows the minimum requirements for an test app:

#include "core/Core.h"
// Example test class to show simple test anatomy.
class ExampleTest: public jm::Test
{
public:
// Constructor
ExampleTest():Test()
{
setName("Example Test");
};
// Mandatory overridden test method. The heart of the test!
void doTest() override
{
int32 a=2;
int32 b=5;
testEquals(a,b,"a is not b");
a=5;
testEquals(a,b,"a is not b");
};
};
// Entry method of test application
int main( int argc, const char* argv[] )
{
// init Jameo System
jm::System::log( "Example Test Suite" , jm::LogLevel::kInformation );
// init test vector
jm::TestVector* vec = new jm::TestVector(argc, argv);
vec->addTest( new ExampleTest() );
// Execute test vector
int32 result = static_cast<int32>(vec->execute());
// Clean up
delete vec;
// Return the number of errors to help calling scripts
return result;
}
static void quit()
This method cleans up static system objects. After calling this method, the program must be terminate...
static void log(const String &message, LogLevel logLevel)
Logs a message.
static void init(const jm::String &bundleId)
This method must be called first to set up important static objects.
A TestVector is a collection of several tests and will execute them all and return the number of erro...
Definition Test.h:336
void addTest(Test *test)
Adds test to the test vector.
size_t execute()
Executes the test vector.
This base class represents a test object. It is used to implement unit tests for any code....
Definition Test.h:119
virtual void doTest()=0
This is the main test method, which must be implemented by every derived test class.
void setName(const String &name)
Set the name of the text.
void testEquals(const double actual, const double expected, const String &failmessage) const
This method tests, if double actual is equal to expected under consideration of RESABS.

The console output of the app will be something like:

[2023-11-01T12:15:17.768Z] INFO: Example Test Suite
[2023-11-01T12:15:17.768Z] INFO: Execute Example Test...
[2023-11-01T12:15:17.768Z] ERROR: a is not b '2' '5'
[2023-11-01T12:15:17.768Z] INFO: Test finished! 2 Tests, 1 Errors.
Cycle finished! In total 2 tests, 1 errors, duration 0,000 sec.

Variable Documentation

◆ gErrorCount

size_t jm::gErrorCount

global error count during single test run.

◆ gTestCount

size_t jm::gTestCount

global test count during single test run.

◆ gTotalErrorCount

size_t jm::gTotalErrorCount

global error count over all done tests.

◆ gTotalTestCount

size_t jm::gTotalTestCount

global test count overall done tests.