Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::tests::Test Class Referenceabstract

A basic test class. More...

#include <test.h>

Inheritance diagram for MaxOS::tests::Test:
MaxOS::tests::ConditionalTest

Public Member Functions

 Test (const string &name, TestType type)
 Constructs a Test with a name and type, and registers it with the TestRunner.
 
TestStatus run ()
 Runs the test and returns the result.
 
virtual TestStatus execute ()=0
 Executes the test and returns the status of the test.
 
const stringname () const
 Gets the name of the test.
 
TestType type () const
 Gets the type of the test.
 

Detailed Description

A basic test class.

Definition at line 69 of file test.h.

Constructor & Destructor Documentation

◆ Test()

Test::Test ( const string name,
TestType  type 
)

Constructs a Test with a name and type, and registers it with the TestRunner.

Parameters
nameThe name of the test
typeThe type of the test

Definition at line 21 of file test.cpp.

22: m_name(name),
23 m_type(type)
24{
26}
static void add_test(Test *test)
Adds a test to the test runner.
Definition test.cpp:138
const string & name() const
Gets the name of the test.
Definition test.cpp:68
TestType type() const
Gets the type of the test.
Definition test.cpp:77

References MaxOS::tests::TestRunner::add_test().

Member Function Documentation

◆ execute()

virtual TestStatus MaxOS::tests::Test::execute ( )
pure virtual

Executes the test and returns the status of the test.

Returns
The result of the test execution

Implemented in MaxOS::tests::ConditionalTest.

Referenced by run().

◆ name()

const string & Test::name ( ) const

Gets the name of the test.

Returns
The name of the test

Definition at line 68 of file test.cpp.

68 {
69 return m_name;
70}

◆ run()

TestStatus Test::run ( )

Runs the test and returns the result.

Returns
TestStatus The status of the test after running

Definition at line 33 of file test.cpp.

33 {
34
35 // Run the test
36 auto result = execute();
37 StringBuilder msg;
38
39 // Build the message
40 msg << "Test ";
41 switch(result) {
42 case TestStatus::PASS:
43 msg << "PASSED";
44 break;
45 case TestStatus::SKIP:
46 msg << "SKIPPED";
47 break;
48 case TestStatus::FAIL:
49 msg << "FAILED";
50 break;
51 }
52 msg << " - " << m_name << "\n";
53
54 // Print the outcome
55 if (result == TestStatus::FAIL)
56 Logger::ERROR() << msg.out;
57 else
58 Logger::TEST() << msg.out;
59
60 return result;
61}
static Logger TEST()
Gets active logger set to test level.
Definition logger.cpp:182
static Logger ERROR()
Gets active logger set to ERROR level.
Definition logger.cpp:216
Creates a string using a using a combination of parts with the '<<' operator. Simmilar to the logger.
Definition string.h:97
String out
The output string.
Definition string.h:99
virtual TestStatus execute()=0
Executes the test and returns the status of the test.

References MaxOS::Logger::ERROR(), execute(), MaxOS::StringBuilder::out, and MaxOS::Logger::TEST().

◆ type()

TestType Test::type ( ) const

Gets the type of the test.

Returns
The type of the test

Definition at line 77 of file test.cpp.

77 {
78 return m_type;
79}

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