Carpenter Engine
A C++ game engine with a build once run anywhere solution
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
Testing::TestRunner Class Reference

A Unit tester used to run C++ unit tests. More...

#include <Testing.hpp>

Public Member Functions

void addTest (std::string name, std::function< void()> test)
 
void runTests ()
 
void DebugLog (std::string message)
 
void DebugError (std::string message)
 
void Assert (bool condition, std::string message)
 
void PrintLogs ()
 
unsigned int getTestCount ()
 
unsigned int getPassedTestCount ()
 

Static Public Member Functions

static TestRunnergetInstance (std::string name="Test")
 

Detailed Description

A Unit tester used to run C++ unit tests.

The goal of this class is to run C++ unit tests for WebAssembly. This class is a singleton that is accessed with Testing::TestRunner::getInstance() and you add tests with Testing::TestRunner::addTest(). These tests get processed and compiled to WASM before being run via JavaScript and running table test. There are extern functions defined in the Testing.cpp file that you can access to run tests.

Warning
This class is a singleton and should not be created manually. It is a singleton that is accessed with Testing::TestRunner::getInstance() and should be assigned to references of the class.

Example

#include <Testing.hpp>
using namespace Testing;
TestRunner& runner{TestRunner::getInstance("Basic Tests")};
int main() {
runner.addTest("Add Two Numbers", []() {
runner.Assert(2 + 2 == 4, "2 + 2 should equal 4!");
});
return 0;
}
A Unit tester used to run C++ unit tests.
Definition Testing.hpp:53
static TestRunner & getInstance(std::string name="Test")
Definition Testing.cpp:11
Author
Roberto Selles
BigChungus21220

Member Function Documentation

◆ addTest()

void Testing::TestRunner::addTest ( std::string  name,
std::function< void()>  test 
)

Adds a test to the test runner

Parameters
nameThe name of the test
testThe test function

◆ Assert()

void Testing::TestRunner::Assert ( bool  condition,
std::string  message 
)

Asserts that the condition is true. If the condition is false, an error message will be printed in the logs via TestRunner::DebugError()

Example

runner.Assert(2 + 2 == 4, "2 + 2 should equal 4!");
Parameters
conditionThe condition to assert
messageThe message to print

◆ DebugError()

void Testing::TestRunner::DebugError ( std::string  message)

Logs an error message to the test being run

Parameters
messageThe message to print

◆ DebugLog()

void Testing::TestRunner::DebugLog ( std::string  message)

Logs a message to the test being run inside Use this instead of std::cout to log messages inside tests

Parameters
messageThe message to print

◆ getInstance()

Testing::TestRunner & Testing::TestRunner::getInstance ( std::string  name = "Test")
static

Returns an instance of the test runner

Warning
When using its return value, make sure you are assigning it to a reference.

◆ getPassedTestCount()

unsigned int Testing::TestRunner::getPassedTestCount ( )

Returns the number of tests that have passed

Returns
unsigned int number of tests that have passed

◆ getTestCount()

unsigned int Testing::TestRunner::getTestCount ( )

Returns the number of tests that have been run

Returns
unsigned int number of tests in the test runner

◆ PrintLogs()

void Testing::TestRunner::PrintLogs ( )

Prints and dequeues all the logs in the logs vector. This is called by runTests() after each test

◆ runTests()

void Testing::TestRunner::runTests ( )

Runs all the tests, processes, and outputs the results. This is called by the table test command so it is not meant to be called manually.


The documentation for this class was generated from the following files: