
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

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
- 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
Mateusz Łoskot wrote: 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; }

"Mateusz Loskot"
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.
Docs are not ready yet. Most of it is either outdated or incomplete.
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?
No. You could have any number of those in a single test module. You sould use your own judgement to decide when to split your test module into separtate executable. Usually reasons more or less clear: * Different units/subsytem needs to have separate executable * If some feature may casue compilation error - move it into separate module. * If number of test module execution time exceed some limit (your choice) - split it.
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
- uses defines cases using BOOST_AUTO_TEST_CASE - or defines suites of cases using BOOST_TEST_SUITE + BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_SUITE
will be a separate program. Right?
No. You could combine several test files into single test module. Don't forget - BOOST_TEST_MAIN/BOOST_TEST_MODULE should be defined into single one only. Gennadiy

Gennadiy Rozental wrote:
"Mateusz Loskot"
wrote: 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?
No. You could have any number of those in a single test module.
And that's explains everything. One test module (a .cpp file) will produce one executable. But in one test module many test cases/suites can be included. Clear.
You sould use your own judgement to decide when to split your test module into separtate executable. Usually reasons more or less clear: * Different units/subsytem needs to have separate executable * If some feature may casue compilation error - move it into separate module. * If number of test module execution time exceed some limit (your choice) - split it.
Great tips! Thanks a lot!
will be a separate program. Right?
No. You could combine several test files into single test module. Don't forget - BOOST_TEST_MAIN/BOOST_TEST_MODULE should be defined into single one only.
Yes, that explains me all: "combine several test files into single test module." Thanks -- Mateusz Łoskot http://mateusz.loskot.net
participants (3)
-
Dmitry
-
Gennadiy Rozental
-
Mateusz Łoskot