The QuickTest API is composed of the following C++ macros. Code samples are also given here to demonstrate basic usage.
QT_TEST(testName): Defines a new unit test with the given unique name.
QT_TEST(someTest)
{
...
}
QT_RUN_TESTS: Runs all tests.
int main(void)
{
QT_RUN_TESTS;
}
QT_FAIL(message): Fails unconditionally and prints the given message.
QT_FAIL("TODO: Write test");
QT_PRINT(message): Prints the given message.
std::ostringstream o;
o << "Performance: " << perf << std::endl;
QT_PRINT(oss.str());
QT_SET_OUTPUT(stream): Sets the output stream (i.e. std::ostream) to use for all output messages. Defaults to std::cout.
std::ofstream file("testOutput.txt");
QT_SET_OUTPUT(&file);
QT_CHECK(condition): Checks whether the given condition is true.
QT_CHECK(name == "tyler");
QT_CHECK_EQUAL(value1, value2): Checks whether the first parameter is equal to the second.
QT_CHECK_EQUAL(year, 2005);
QT_CHECK_NOT_EQUAL(value1, value2): Checks whether the first parameter is not equal to the second.
QT_CHECK_NOT_EQUAL(year, 1905);
QT_CHECK_CLOSE(value1, value2, tolerance): Checks whether the first parameter is within the given tolerance from the second parameter. This is useful for comparing floating point values.
QT_CHECK_CLOSE(length, 4.5, 0.002);
QT_CHECK_LESS(value1, value2): Checks whether the first parameter is less than the second.
QT_CHECK_LESS(force, maxLoad);
QT_CHECK_LESS_OR_EQUAL(value1, value2): Checks whether the first parameter is less than or equal to the second.
QT_CHECK_LESS_OR_EQUAL(volume, maxVolume);
QT_CHECK_GREATER(value1, value2): Checks whether the first parameter is greater than the second.
QT_CHECK_GREATER(freeBytes, 1048576);
QT_CHECK_GREATER_OR_EQUAL(value1, value2): Checks whether the first parameter is greater than or equal to the second.
QT_CHECK_GREATER_OR_EQUAL(siteHits, 100);