"Stephen Torri"
I have the following code for a sample test. I was wondering how I can move code that is common to a long off different test files to a common location and use inheritance?
Why would you want to use an inheritance (just a general question)?
In the code below I can do two things. If its indeed generic I can encapsulate it in a common class used in the tests. Secondly I could put test_one and test_two in a class and inherit from the parent generic class. What is the best solution for what I am trying to do?
To be frank with you I do not see anything particular generic in the code below and don't really understand what you are trying to do. Could you please give some more detailes. Than I probably be able to give some recommendations.
Stephen
----------CODE--------------
#include
#include <fstream> using namespace boost::unit_test; using namespace boost::unit_test_framework;
You don't need secont using statement. Both namespaces are synonims.
class A {} class B {}
A* helper_run_test ( B& target_ref, std::string target_file ) { ... do work on B and return A* result }
void test_one () { B& b_ref;
That's invalid
A* helper_run_test ( b, "Apple" ); .. perform a BOOST_CHECK_EQUAL }
void test_two () { B& b_ref; A* helper_run_test ( b, "Peach" ); .. perform a BOOST_CHECK_EQUAL }
test_suite* init_unit_test_suite ( int, char**) { test_suite* test = BOOST_TEST_SUITE ("My test suite");
test->add ( BOOST_TEST_CASE ( &test_one ) ); test->add ( BOOST_TEST_CASE ( &test_two ) );
return test; }
I recommend you to avoid init_unit_test_suite and use BOOST_AUTO_TEST_CASE instead. Gennadiy