Example Test Case with simple int main().
Example Test Case with simple int main().
#include <cstring>
#include <iostream>
#include <string>
int
main(
int argc,
char**argv
)
{
}
const std::string initialString = "This is a test string!";
std::string testString;
void setup()
{
testString = initialString;
assertEqual(initialString, testString,
"No change has been made");
}
void teardown()
{
testString.clear();
assertEqual(0, testString.length(),
"Length should be zero");
}
{
assertEqual(initialString, testString,
"No change has been made");
}
{
testString.clear();
assertEqual(std::string(), testString,
"Should be empty string");
assertEqual(0, testString.length(),
"Length should be zero");
}
{
testString = "";
assertEqual(std::string(), testString,
"Should be empty string");
assertEqual(0, testString.length(),
"Length should be zero");
}
{
testString = "";
assertEqual(std::string(), testString,
"Should be empty string");
testString = initialString;
assertEqual(initialString, testString,
"Should match after assignment");
assertEqual(strlen(initialString.c_str()), testString.length(),
"Compare length against c string");
assertEqual(strlen(initialString.c_str()), strlen(testString.c_str()),
"Compare length of both as c strings");
assertEqual(0, strncmp(initialString.c_str(), testString.c_str(), initialString.length()),
"Compare both as c strings");
assertEqual(initialString, testString.c_str(),
"Should match as c string after assignment");
}
#define assertEqual(first, second, message)
Fail this test if (first) is not equal to (second) with the given message as explanation.
#define TEST_SUITE_END()
Finish definition of a Test Suite started with TEST_SUITE().
#define TEST_CASE(testCaseName)
Defines a Test Case method named testCaseName within a Test Suite defined by TEST_SUITE().
#define TEST_SUITE(testSuiteName)
Defines a Test Suite named testSuiteName.
Count of tests run, and fails.
int fails
Number of tests that have failed.
Stream-based Logger for events while running tests.
Count run(Logger &logger) const
Run all tests that have been add()ed.
static TestRunner & get()
Get the singleton.