1#ifndef JON_TEST_TEST_CASE_H
2#define JON_TEST_TEST_CASE_H
16template <
typename TestSuiteDerived>
36 const char*
const testCaseName,
55 const char*
const testCaseName,
83 logger.
errorCase(suite.getName(),
name,
"(internal)",
"Internal Error: MISSING test case method");
88 bool setupPassed =
false;
89 try { suite.setup(); setupPassed =
true; }
91 catch(std::exception& unexpected) { logger.
exceptionCase(suite.getName(),
name,
"setup", unexpected); }
92 catch(...) { logger.
errorCase(suite.getName(),
name,
"setup",
"UNKNOWN EXCEPTION"); }
94 bool casePassed =
false;
98 catch(std::exception& unexpected) { logger.
exceptionCase(suite.getName(),
name,
"case", unexpected); }
99 catch(...) { logger.
errorCase(suite.getName(),
name,
"case",
"UNKNOWN EXCEPTION"); }
102 bool teardownPassed =
false;
103 try { suite.teardown(); teardownPassed =
true; }
105 catch(std::exception& unexpected) { logger.
exceptionCase(suite.getName(),
name,
"teardown", unexpected); }
106 catch(...) { logger.
errorCase(suite.getName(),
name,
"teardown",
"UNKNOWN EXCEPTION"); }
108 const bool passed = setupPassed && casePassed && teardownPassed;
Interface for logging events while running tests.
virtual void exceptionCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const std::exception &unexpected)=0
Unexpected exception occurred during a part of the case.
virtual void startCase(const std::string &suiteName, const std::string &caseName)=0
Start of test case.
virtual void failCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const TestFailure &failure)=0
Test failure occurred during a part of the case.
virtual void endCase(const std::string &suiteName, const std::string &caseName, const bool pass)=0
End of test case, with record pass or fail.
virtual void errorCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const std::string &message)=0
Unexpected error occurred during a part of the test case.
Defines and runs a single Test Case within a Test Suite.
TestCase(const TestCase &right)=default
Default copy constructor for use in STL containers.
std::string name
Name of the Test Case.
~TestCase()
Do nothing destructor.
TestCaseMethod testCaseMethod
TestSuite method of the Test Case.
TestCase(const char *const testCaseName, TestCaseMethod const testCaseMethod)
Create Test Case by name for given testCaseMethod in TestSuite.
TestCase()=default
Default initializer for use in STL containers.
void(TestSuite::* TestCaseMethod)()
The actual Test Suite Method type for test cases.
TestSuiteDerived TestSuite
The actual Test Suite class.
bool run(TestSuite &suite, Logger &logger) const
Run this Test Case as part of suite, logging events to logger.
static TestCase createAndAdd(TestSuite &suite, const char *const testCaseName, TestCaseMethod const testCaseMethod)
Creates TestCase and adds the Test Case to the suite.
Exception thrown when a test fails an assert and should fail (unless wrapped in expectedFailure()).