MQLUNIT
Public Member Functions | List of all members
MQLUNIT_TestCase Class Referenceabstract

A test case defines the fixture to run multiple tests. More...

Inheritance diagram for MQLUNIT_TestCase:
Inheritance graph
[legend]

Public Member Functions

 MQLUNIT_TestCase ()
 Constructor : creates a test case using a class name as a test case name. More...
 
 MQLUNIT_TestCase (const string name)
 Constructor : creates a test case with a provided name. More...
 
virtual ~MQLUNIT_TestCase ()
 Destructor. More...
 
virtual void setUp ()
 Set up context before running a test. More...
 
virtual void tearDown ()
 Clean up after the test run. More...
 
virtual void run (MQLUNIT_TestResult *result, bool inherited=false)=0
 Runs the tests. More...
 
- Public Member Functions inherited from MQLUNIT_Test
 MQLUNIT_Test ()
 Constructor : creates a test using a class name as a test name. More...
 
 MQLUNIT_Test (const string name)
 Constructor : creates a test with a provided test name. More...
 
virtual ~MQLUNIT_Test ()
 Destructor. More...
 
string getName ()
 Returns a name of a test. More...
 

Detailed Description

A test case defines the fixture to run multiple tests.

To define a test case:
1) implement a subclass of MQLUNIT_TestCase
2) define instance variables that store the state of the fixture
3) initialize the fixture state by overriding MQLUNIT_TestCase::setUp
4) clean-up after a test by overriding MQLUNIT_TestCase::tearDown

Each test runs in its own fixture so there can be no side effects among test runs.

For example:

class MathTest : public MQLUNIT_TestCase {
private:
double a, b;
public:
MathTest() : MQLUNIT_TestCase(typename(this)) {};
MathTest(string name) : MQLUNIT_TestCase(name) {};
void setUp() { a = 1.0; b = 2.0; };
TEST_START(Add) {
double result = a + b;
ASSERT_TRUE("Must add doubles", result == 4.0);
}
MQLUNIT_END
};

The tests to be run can be collected into an MQLUNIT_TestSuite.

suite.addTest(new MyFirstTestCase());
suite.addTest(new MySecondTestCase());
suite.addTest(new MyThirdTestCase());
runner.run(&suite);
See also
MQLUNIT_TestResult
MQLUNIT_TestSuite

Constructor & Destructor Documentation

◆ MQLUNIT_TestCase() [1/2]

MQLUNIT_TestCase::MQLUNIT_TestCase ( )
inline

Constructor : creates a test case using a class name as a test case name.

◆ MQLUNIT_TestCase() [2/2]

MQLUNIT_TestCase::MQLUNIT_TestCase ( const string  name)
inline

Constructor : creates a test case with a provided name.

Parameters
name: test case name

◆ ~MQLUNIT_TestCase()

virtual MQLUNIT_TestCase::~MQLUNIT_TestCase ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ run()

virtual void MQLUNIT_TestCase::run ( MQLUNIT_TestResult result,
bool  inherited = false 
)
pure virtual

Runs the tests.

Parameters
result: collects the results of executing a test case
inherited: set to true to tell the test it has been inherited from and is run by a child test
See also
MQLUNIT_TestResult

Implements MQLUNIT_Test.

◆ setUp()

virtual void MQLUNIT_TestCase::setUp ( )
inlinevirtual

Set up context before running a test.

◆ tearDown()

virtual void MQLUNIT_TestCase::tearDown ( )
inlinevirtual

Clean up after the test run.


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

Copyright © 2017 Eneset Group Trust