Boost logo

Boost Users :

From: Dmitry (dmitry_at_[hidden])
Date: 2006-03-06 08:44:02


Mateusz Łoskot wrote:
> Hi,
>
> I'd like to ask yet another questions related to Unit Test Framework
> usage. Especially, I'm interested in best practice of Unit Tests
> organization in the project.
>
> I have a project that consists of more than 100 classes.
> Some of those classes are general purpose (e.g. Point) but some are
> organized in components (e.g. spatial index component consisting of 5
> classes).
>
> Now, I'd like to add Unit Tests (yes, I know I should have them prepared
> before I created those classes ;-)).
>
> I've read almost all docs about Boost.Test, downloaded from CVS.
> I know how to create Test Case and how to combine those cases into Test
> Suite. I also read introductory docs from "Tutorials and usage
> recommendations" part as well as I walked through unit_test_examples but
> I'm still a bit confused about the bigger picture.
>
> As far as I understand, every Test Case or Test Suite of cases is to be
> compiled to separate executable. Is this correct?
> So, unit_test_example_01.cpp and unit_test_example_02.cpp and so on
> create separate programs that can be executed e.g. from Visual Studio
> Post-Build Event as explained in docs.
>
> More precisely, every .cpp file that:
> - include #include <boost/test/unit_test.hpp>
> - uses defines cases using BOOST_AUTO_TEST_CASE
> - or defines suites of cases using BOOST_TEST_SUITE + BOOST_AUTO_TEST_CASE
>
> will be a separate program. Right?
>
> So, if I have 100 classes and I'd like to define Test Suite,
> with a number of Test Cases in every suite, for every my class
> then should I expect I will get 100 test executables?
>
> From Visual Studio point of view, I will have 100 projects in my test
> solution. Am I right?
>
> I feel I don't understand something, so I'd be very thankful for some
> light on this subject.
>
> So, what is the best way to organize Test Cases and Suites for my 100
> classes? Should I try to build them into one executable or into number
> of separate executables as described in my assumptions above?
>
> If there are e.g. 100 executables for my 100 tests, how should I run
> them e.g. during complete rebuild of project using automake or bjam?
> Not using Visual Studio Post-Build Events, should I run those tests from
> makefiles/jamfiles or there is a kind of test runner program I can use?
>
> Best regards
Hi again Mateusz,
You can do something like following (again if I understand you
correctly, because it seems to me that I sticked with exacly the same
problems))
//Note: all objects will be destroyed before test execution
test_suite* init_unit_test_suite( int argc, char* argv[] )
{
        test_suite* master_test_unit = BOOST_TEST_SUITE("Master");
        Graph input_graph(0);
        if (input_data(/**/argv[1], input_graph) == false) {
                std::cerr << "Some error in input data, unable to proceed!" << std::endl;
                return (test_suite*)0;
        }
        init_vertex_index(input_graph);
        static Graph test_graph(add_complementary_edges(input_graph));
        CSequentialCircuit test_circuit(test_graph);

        test_suite* recycling_tests = BOOST_TEST_SUITE( "recycling test" );
     recycling_tests->add( BOOST_PARAM_TEST_CASE( &test5_recycling,
&test_circuit, &test_circuit + 1 ) );

        /**Add test suites here in order to run them**/
        master_test_unit->add(recycling_tests);
        master_test_unit->add(new mcr_Howard_test_suite(test_graph));
        return master_test_unit;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net