libept
Public Member Functions | Public Attributes | List of all members
ept::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 ept::tests::TestCase:
ept::tests::FixtureTestCase< FIXTURE >

Public Member Functions

 TestCase (const std::string &name)
 
virtual ~TestCase ()
 
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.
 
template<typename ... Args>
void add_method (const std::string &name, std::function< void()> test_function)
 Register a new test method.
 
template<typename ... Args>
void add_method (const std::string &name, std::function< void()> test_function, Args &&... args)
 Register a new test method.
 
template<typename FUNC , typename ... Args>
void add_method (const std::string &name, FUNC test_function, Args &&... args)
 Register a new test metheod, with arguments.
 

Public Attributes

std::string name
 Name of the test case.
 
std::vector< TestMethodmethods
 All registered test methods.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ TestCase()

ept::tests::TestCase::TestCase ( const std::string &  name)
inline

◆ ~TestCase()

virtual ept::tests::TestCase::~TestCase ( )
inlinevirtual

Member Function Documentation

◆ add_method() [1/3]

template<typename FUNC , typename ... Args>
void ept::tests::TestCase::add_method ( const std::string &  name,
FUNC  test_function,
Args &&...  args 
)
inline

Register a new test metheod, with arguments.

Any extra arguments to the function will be passed to the test method.

References methods, and name.

◆ add_method() [2/3]

template<typename ... Args>
void ept::tests::TestCase::add_method ( const std::string &  name,
std::function< void()>  test_function 
)
inline

Register a new test method.

References methods, and name.

Referenced by register_tests().

◆ add_method() [3/3]

template<typename ... Args>
void ept::tests::TestCase::add_method ( const std::string &  name,
std::function< void()>  test_function,
Args &&...  args 
)
inline

Register a new test method.

References methods, and name.

◆ method_setup()

virtual void ept::tests::TestCase::method_setup ( TestMethodResult )
inlinevirtual

Set up before the test method is run.

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

Referenced by ept::tests::FixtureTestCase< FIXTURE >::method_setup(), and run_test().

◆ method_teardown()

virtual void ept::tests::TestCase::method_teardown ( TestMethodResult )
inlinevirtual

Clean up after the test method is run.

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

Referenced by ept::tests::FixtureTestCase< FIXTURE >::method_teardown(), and run_test().

◆ register_tests()

virtual void ept::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().

Referenced by register_tests().

◆ run_test()

TestMethodResult ept::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.

References method_setup(), method_teardown(), ept::tests::TestMethod::name, name, res, ept::tests::TestMethod::test_function, ept::tests::TestController::test_method_begin(), and ept::tests::TestController::test_method_end().

Referenced by run_tests().

◆ run_tests()

TestCaseResult ept::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().

References methods, name, res, run_test(), setup(), teardown(), ept::tests::TestController::test_case_begin(), and ept::tests::TestController::test_case_end().

◆ setup()

virtual void ept::tests::TestCase::setup ( )
inlinevirtual

Set up the test case before it is run.

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

Referenced by run_tests(), and ept::tests::FixtureTestCase< FIXTURE >::setup().

◆ teardown()

virtual void ept::tests::TestCase::teardown ( )
inlinevirtual

Clean up after the test case is run.

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

Referenced by run_tests(), and ept::tests::FixtureTestCase< FIXTURE >::teardown().

Member Data Documentation

◆ methods

std::vector<TestMethod> ept::tests::TestCase::methods

◆ name

std::string ept::tests::TestCase::name

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