xunittest/test.h File Reference
Go to the source code of this file.
|
Classes |
| class | XUnitTestResult |
| class | XUnitTestResult::Event |
| class | XUnitTestHtmlResult |
| class | XUnitTestXmlResult |
| class | XUnitTestSetup |
| class | XUnitTest |
| class | XUnitTestFactory |
Defines |
| #define | TEST(aGroup, aName) XUNITTEST(aGroup, aName) |
| #define | TESTWITHSETUP(aGroup, aName) XUNITTESTWITHSETUPCLASS(aGroup, aName, aGroup##Setup) |
| #define | TESTWITHSETUPCLASS(aGroup, aName, aClass) XUNITTESTWITHSETUPCLASS(aGroup, aName, aClass) |
| #define | CHECK(aCond) |
| #define | CHECKDESC(aCond, aDesc) |
| #define | INFO(aText) result()->info(__FILE__, __LINE__, #aText) |
| #define | INFOSTR(aText) result()->info(__FILE__, __LINE__, aText) |
| #define | INFOTXT(aText) result()->info(0, 0, aText) |
| #define | PASS(aText) result()->success(__FILE__, __LINE__, #aText) |
| #define | PASSSTR(aText) result()->success(__FILE__, __LINE__, aText) |
| #define | FAIL(aText) result()->failure(__FILE__, __LINE__, #aText) |
| #define | FAILSTR(aText) result()->failure(__FILE__, __LINE__, aText) |
Detailed Description
- Author:
- Copyright (C) 2008 Chris Croughton <swdev@keristor.co.uk> Unit testing classes and macros
This unit testing structure is based loosely on the ideas of CppUnitLite by Michael Feathers. However, it is a complete re-write and he has no responsibility for it. It also incorporates ideas from other implementations, notably that of producing HTML output using CSS for highlighting.
Overview of testing
Define Documentation
Value:
do { \
if (aCond) result()->success(__FILE__, __LINE__, #aCond); \
else result()->failure(__FILE__, __LINE__, #aCond); \
} while (0)
Check a condition for boolean
true, calling the appropriate functions for success or failure. Must be called from inside a
TEST() block.
- Parameters:
-
| aCond | boolean condition, will be used as the text in the success or failure call. |
| #define CHECKDESC |
( |
aCond, |
|
|
aDesc |
|
) |
|
Value:
do { \
if (aCond) result()->success(__FILE__, __LINE__, #aDesc); \
else result()->failure(__FILE__, __LINE__, #aDesc); \
} while (0)
Check a condition for boolean
true, calling the appropriate functions for success or failure. Must be called from inside a
TEST() block.
- Parameters:
-
| aCond | Boolean condition |
| aDesc | Description, will be used as the text in the success or failure call. Should not be in quotes. |
| #define FAIL |
( |
aText |
|
) |
result()->failure(__FILE__, __LINE__, #aText) |
Do a call to the failure() result method, passing the text (which shouldn't be in ""). Must be called from inside a TEST() block.
| #define FAILSTR |
( |
aText |
|
) |
result()->failure(__FILE__, __LINE__, aText) |
Do a call to the failure() result method, passing the text as a pointer to a character string. Must be called from inside a TEST() block.
| #define INFO |
( |
aText |
|
) |
result()->info(__FILE__, __LINE__, #aText) |
Do a call to the info() result method, passing the text (which shouldn't be in ""). Must be called from inside a TEST() block.
| #define INFOSTR |
( |
aText |
|
) |
result()->info(__FILE__, __LINE__, aText) |
Do a call to the info() result method, passing the text as a pointer to a character string. Must be called from inside a TEST() block.
| #define INFOTXT |
( |
aText |
|
) |
result()->info(0, 0, aText) |
Do a call to the info() result method, passing the text as a pointer to a character string which will appear allone on a line. Must be called from inside a TEST() block.
| #define PASS |
( |
aText |
|
) |
result()->success(__FILE__, __LINE__, #aText) |
Do a call to the success() result method, passing the text (which shouldn't be in ""). Must be called from inside a TEST() block.
| #define PASSSTR |
( |
aText |
|
) |
result()->success(__FILE__, __LINE__, aText) |
Do a call to the success() result method, passing the text as a pointer to a character string. Must be called from inside a TEST() block.
| #define TEST |
( |
aGroup, |
|
|
aName |
|
) |
XUNITTEST(aGroup, aName) |
Macro to start a test. It creates a derived class of XUnitTest, implementing the XUnitTest::doTest() method, such that the test itself should start immediately (as though TEST(...) was a function declaration). For example:
TEST(group, test)
{
int i = 1;
int j = 2;
CHECK(i == j-1);
}
This will create a test called "group.test".
- Parameters:
-
| aGroup | The name of the test group, generally a class or module name. |
| aName | The name of the test case. |
| #define TESTWITHSETUP |
( |
aGroup, |
|
|
aName |
|
) |
XUNITTESTWITHSETUPCLASS(aGroup, aName, aGroup##Setup) |
Macro to start a test, using a setup class named by the test group name plus Setup. It creates a derived class of XUnitTest, implementing the XUnitTest::doTest() method, such that the test itself should start immediately (as though TESTWITHSETUP(...) was a function declaration). For example:
class groupSetup
{
public:
int var;
virtual void setup()
{
var = 42;
}
};
TESTWITHSETUP(group, test)
{
CHECK(var == 42);
}
This will create a test called "group.test", which has a member variable var which is initialised to 42 before the test is executed.
- Parameters:
-
| aGroup | The name of the test group, generally a class or module name. |
| aName | The name of the test case. |
| #define TESTWITHSETUPCLASS |
( |
aGroup, |
|
|
aName, |
|
|
aClass |
|
) |
XUNITTESTWITHSETUPCLASS(aGroup, aName, aClass) |
Macro to start a test, using a named setup class. It creates a derived class of XUnitTest, implementing the XUnitTest::doTest() method, such that the test itself should start immediately (as though TEST(...) was a function declaration). For example:
class MySetup
{
public:
int var;
virtual void setup()
{
var = 99;
}
};
TESTWITHSETUPCLASS(group, test, MySetup)
{
CHECK(var+1 == 100);
}
This will create a test called "group.test" using the setup class MySetup. The advantage of this is that some tests can share a setup class and others use a different one, rather than it being tied to the test group name.
- Parameters:
-
| aGroup | The name of the test group, generally a class or module name. |
| aName | The name of the test case. |
| aClass | The name of the setup class. |