wreport::tests::TestCase Struct Referenceabstract

Test case collecting several test methods, and self-registering with the singleton instance of TestRegistry. More...

`#include <tests.h>`

Inheritance diagram for wreport::tests::TestCase:

## Public Member Functions

| TestCase (const std::string &name)
void | register_tests_once ()
| Idempotent wrapper for register_tests().
virtual void | register_tests ()=0
| This will be called before running the test case, to populate it with its test methods.
virtual void | setup ()
| Set up the test case before it is run.
virtual void | teardown ()
| Clean up after the test case is run.
virtual void | method_setup (TestMethodResult &)
| Set up before the test method is run.
virtual void | method_teardown (TestMethodResult &)
| Clean up after the test method is run.
virtual TestCaseResult | run_tests (TestController &controller)
| Call setup(), run all the tests that have been registered, then call teardown().
virtual TestMethodResult | run_test (TestController &controller, TestMethod &method)
| Run a test method.
TestMethod & | add_method (const std::string &name)
| Register a new test method, with the actual test function to be added later.
template<typename ... Args>
TestMethod & | add_method (const std::string &name, std::function< void()> test_function)
| Register a new test method.
template<typename ... Args>
TestMethod & | add_method (const std::string &name, const std::string &doc, std::function< void()> test_function)
| Register a new test method, including documentation.

## Data Fields

std::string | name
| Name of the test case.
std::vector< TestMethod > | methods
| All registered test methods.
bool | tests_registered = false
| Set to true the first time register_tests_once is run.

## Detailed Description

Test case collecting several test methods, and self-registering with the singleton instance of TestRegistry.

## Member Function Documentation

## method_setup()

virtual void wreport::tests::TestCase::method_setup | ( | TestMethodResult & |  | ) |

inline virtual

Set up before the test method is run.

Reimplemented in wreport::tests::FixtureTestCase< FIXTURE >.

Referenced by wreport::tests::FixtureTestCase< FIXTURE >::method_setup().

## method_teardown()

virtual void wreport::tests::TestCase::method_teardown | ( | TestMethodResult & |  | ) |

inline virtual

Clean up after the test method is run.

Reimplemented in wreport::tests::FixtureTestCase< FIXTURE >.

Referenced by wreport::tests::FixtureTestCase< FIXTURE >::method_teardown().

## register_tests()

virtual void wreport::tests::TestCase::register_tests | ( |  | ) |

pure virtual

This will be called before running the test case, to populate it with its test methods.

This needs to be reimplemented with a function that will mostly be a sequence of calls to add_method().

## run_test()

virtual TestMethodResult wreport::tests::TestCase::run_test | ( | TestController & | controller,
|  | TestMethod & | method )

virtual

Run a test method.

Call method_setup(), run all the tests that have been registered, then call method_teardown().

Exceptions thrown by the test method are caught and reported in TestMethodResult.

Exceptions in method_setup() and method_teardown() are caught and reported in TestMethodResult.

## run_tests()

virtual TestCaseResult wreport::tests::TestCase::run_tests | ( | TestController & | controller | ) |

virtual

Call setup(), run all the tests that have been registered, then call teardown().

Exceptions in setup() and teardown() are caught and reported in TestCaseResult. Test are run using run_test().

## setup()

virtual void wreport::tests::TestCase::setup | ( |  | ) |

inline virtual

Set up the test case before it is run.

Reimplemented in wreport::tests::FixtureTestCase< FIXTURE >.

Referenced by wreport::tests::FixtureTestCase< FIXTURE >::setup().

## teardown()

virtual void wreport::tests::TestCase::teardown | ( |  | ) |

inline virtual

Clean up after the test case is run.

Reimplemented in wreport::tests::FixtureTestCase< FIXTURE >.

Referenced by wreport::tests::FixtureTestCase< FIXTURE >::teardown().

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

- utils/tests.h