TestUnit - builing hierarchical tests

Hello group. I want to use Boost.UnitTest library for my code testing. I went thru examples and I've found it useful and easy. It's easy on simple one-method one-file examples. My problem begun when I wanted to build few hierarchical test suites splitted into directories and files. I failed. There is no example on boost page - how to write them splitted in a few files. Only cases are pointers to functions in one file. I had problems including unit test header - I had multiple definitions of boost classes. When i removed header - there were no macros etc. Can anyone share a good practice - how to wrap example1 and example2 to one mainsuite? And use 3 files for it? Examples from tutorial: http://www.pdc.kth.se/training/Talks/C++/boost/libs/test/doc/components/unit... On a side note I find myself disappointed with Boost.UnitTest documentation. It isn't easy to follow (like I did for example with Boost.Regex) . Links to examples are broken on main site : http://www.boost.org/libs/test/doc/components/utf/index.html. But there's a mirror on http://www.pdc.kth.se/training/Talks/C++/boost/libs/test/doc/components/unit.... That's nice, but their latest revision is more than 4 years old! But when you google enough you find another one - author's own - on http://www.patmedia.net/~rogeeff/html/ revised 2007 (at least copyright is 2007). Is it the way Boost library documentation is meant to be? On a second side note I had no "main ()" function problem on debian. There were changes on 1.34.0 so it won't work anymore as documentation says. So I had to dig thru bug reports, mailing lists to find out author's personal note on these changes. As a library user I don't want to waste time googling, I want to use documentation and get it working. I belive Boost.UnitTest is a good work so don't waste it on a poor support! Greetings, Tomasz Kalkosiński

"Tomasz Kalkosinski" <pppsp@gazeta.pl> wrote in message news:op.t363onxw2fp26v@localhost...
Hello group.
I want to use Boost.UnitTest library for my code testing. I went thru examples and I've found it useful and easy. It's easy on simple one-method one-file examples. My problem begun when I wanted to build few hierarchical test suites splitted into directories and files. I failed.
There shouldn't be any problems. But donlt forget - Boost.Test only deals with test suites within single test module (single and multifile). To manage multiple test modules you need another level - Build/Test system. Why don't you post specific problems with faling test modules examples.
That's nice, but their latest revision is more than 4 years old! But when you google enough you find another one - author's own - on http://www.patmedia.net/~rogeeff/html/ revised 2007 (at least copyright is 2007). Is it the way Boost library documentation is meant to be?
Unfortunately documentation update takes much longer than it should be. The link above is you best shot at this point. Thisis beta version of an updated docs. I am still working on final version. Gennadiy

On Wed, 02 Jan 2008 04:57:28 +0100, Gennadiy Rozental <rogeeff@gmail.com> wrote:
Why don't you post specific problems with faling test modules examples.
My problem is easy. I want to have one main test that add Second and so on. I cannot get it to work :/ What's the best practice? Is BOOST_CLASS_TEST_CASE a good approach on Second? I cannot get add to work :/ I definitely need an example with two file, parent and child test example. Thanks in advance, Tomasz Kalkosiński //First #include <boost/test/included/unit_test.hpp> #include "second.cpp" using boost::unit_test::test_suite; // most frequently you implement test cases as a free functions void free_test_function() { // reports 'error in "free_test_function": test 2 == 1 failed' BOOST_CHECK(2 == 1); // non-critical test => continue after failure int* p = (int*)0; *p = 0; } test_suite* init_unit_test_suite( int, char* [] ) { test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); // this example will pass cause we know ahead of time number of expected failures test->add( BOOST_TEST_CASE( &free_test_function ), 1 /* expected one error */ ); test->add (new Second ()); return test; } //EOF //Second #include <boost/test/included/unit_test.hpp> using boost::unit_test::test_suite; class Second : public test_suite { public: Second () : test_suite ("Second test suite") { add (BOOST_CLASS_TEST_CASE(&free_test_function2)); } // most frequently you implement test cases as a free functions void free_test_function2() { // reports 'error in "free_test_function": test 2 == 1 failed' BOOST_CHECK(2 == 1); // non-critical test => continue after failure int* p = (int*)0; *p = 0; } } ;

Hi Tomasz, On Sat, Jan 05, 2008 at 01:24:26AM +0100, Tomasz Kalkosiński wrote:
My problem is easy. I want to have one main test that add Second and so on. I cannot get it to work :/ What's the best practice? Is BOOST_CLASS_TEST_CASE a good approach on Second? I cannot get add to work :/ I definitely need an example with two file, parent and child test example.
I use similar test cases. Please note that my code is probably not perfect as I use for example manuel test registration and still need to adapt the code (using some autotools determined macros) to avoid the static/shared library fiasco but it works at least with older Boost code ... The following code is extracted from my project and mainly uses the fact that one can add test suites as well as simple test functions to other test suites. So it's easy to create hierarchies. I think I once just tried it and it worked. Not sure whether it can be found in the old or new documentation. /******************************************************/ // test.cpp #include <boost/test/unit_test.hpp> using boost::unit_test::test_suite; test_suite* Jacobi_test_suite(); test_suite* GaussSeidel_test_suite(); test_suite* init_unit_test_suite(int, char *[]) { test_suite *test = BOOST_TEST_SUITE("Master test suite"); BOOST_MESSAGE("solver tests"); test->add(Jacobi_test_suite()); test->add(GaussSeidel_test_suite()); return test; } /******************************************************/ // Jacobi_test.cpp #include "../Jacobi.h" #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> #include <stdexcept> using boost::unit_test::test_suite; void JacobiTest1() { DenseMatrix A(2, 3); Vektor x(3, 1.0); Vektor y(2, 1.0); Jacobi jacobi; BOOST_CHECK_THROW(jacobi.solve(A, x, y), std::logic_error); } test_suite* Jacobi_test_suite() { test_suite *test = BOOST_TEST_SUITE("Jacobi iteration test suite"); BOOST_MESSAGE("Jacobi tests"); test->add(BOOST_TEST_CASE(&JacobiTest1)); return test; } /******************************************************/ // GaussSeidel_test.cpp #include "../GaussSeidel.h" #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> #include <stdexcept> using boost::unit_test::test_suite; void GaussSeidelTest4() { DenseMatrix A(3, 3); Vektor x(3); Vektor y(3); GaussSeidel gs1("damped Gauß-Seidel (SOR)", 0.5, 1); // 1 iteration gs1.solve(A, x ,y); BOOST_CHECK_CLOSE(X[0], -108.0/240, 1E-10); BOOST_CHECK_CLOSE(X[1], -27.0/240, 1E-10); BOOST_CHECK_CLOSE(X[2], 38.0/240, 1E-10); } test_suite* GaussSeidel_test_suite() { test_suite *test = BOOST_TEST_SUITE("Gauß-Seidel iteration test suite"); BOOST_MESSAGE("Gauß-Seidel tests"); test->add(BOOST_TEST_CASE(&GaussSeidelTest4)); return test; } Hope it helps, Jens

"Jens Seidel" <jensseidel@users.sf.net> wrote in message news:20080105024939.GA2444@imkf-pc073.imkf.tu-freiberg.de...
Hi Tomasz,
On Sat, Jan 05, 2008 at 01:24:26AM +0100, Tomasz Kalkosinski wrote:
My problem is easy. I want to have one main test that add Second and so on. I cannot get it to work :/ What's the best practice? Is BOOST_CLASS_TEST_CASE a good approach on Second? I cannot get add to work :/ I definitely need an example with two file, parent and child test example.
I use similar test cases. Please note that my code is probably not perfect as I use for example manuel test registration and still need to adapt the code (using some autotools determined macros) to avoid the static/shared library fiasco but it works at least with older Boost code
I must say you are comming a bit strong here, don't you think? The fact that you were using unsupported configuration which doesn't work anymore is IMO minor inconvinience.
The following code is extracted from my project and mainly uses the fact that one can add test suites as well as simple test functions to other test suites. So it's easy to create hierarchies. I think I once just tried it and it worked. Not sure whether it can be found in the old or new documentation.
/******************************************************/ // test.cpp #include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
test_suite* Jacobi_test_suite(); test_suite* GaussSeidel_test_suite();
test_suite* init_unit_test_suite(int, char *[]) { test_suite *test = BOOST_TEST_SUITE("Master test suite"); BOOST_MESSAGE("solver tests"); test->add(Jacobi_test_suite()); test->add(GaussSeidel_test_suite());
return test; }
All you need in this file is #define BOOST_TEST_MAIN #include <boost/test/unit_test.hpp>
/******************************************************/ // Jacobi_test.cpp
#include "../Jacobi.h"
#include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> #include <stdexcept>
using boost::unit_test::test_suite;
void JacobiTest1() { DenseMatrix A(2, 3); Vektor x(3, 1.0); Vektor y(2, 1.0); Jacobi jacobi; BOOST_CHECK_THROW(jacobi.solve(A, x, y), std::logic_error); }
test_suite* Jacobi_test_suite() { test_suite *test = BOOST_TEST_SUITE("Jacobi iteration test suite"); BOOST_MESSAGE("Jacobi tests"); test->add(BOOST_TEST_CASE(&JacobiTest1));
return test; }
This file may look like this: #include "../Jacobi.h" #include <boost/test/unit_test.hpp> #include <stdexcept> BOOST_AUTO_TEST_SUITE( Jacobi_iteration_test_suite ) BOOST_AUTO_TEST_CASE( JacobiTest1 ) { DenseMatrix A(2, 3); Vektor x(3, 1.0); Vektor y(2, 1.0); Jacobi jacobi; BOOST_CHECK_THROW(jacobi.solve(A, x, y), std::logic_error); } BOOST_AUTO_TEST_SUITE_END()
/******************************************************/ // GaussSeidel_test.cpp
#include "../GaussSeidel.h"
#include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> #include <stdexcept>
using boost::unit_test::test_suite;
void GaussSeidelTest4() { DenseMatrix A(3, 3); Vektor x(3); Vektor y(3); GaussSeidel gs1("damped Gau?-Seidel (SOR)", 0.5, 1); // 1 iteration gs1.solve(A, x ,y); BOOST_CHECK_CLOSE(X[0], -108.0/240, 1E-10); BOOST_CHECK_CLOSE(X[1], -27.0/240, 1E-10); BOOST_CHECK_CLOSE(X[2], 38.0/240, 1E-10); }
test_suite* GaussSeidel_test_suite() { test_suite *test = BOOST_TEST_SUITE("Gau?-Seidel iteration test suite"); BOOST_MESSAGE("Gau?-Seidel tests"); test->add(BOOST_TEST_CASE(&GaussSeidelTest4)); return test; }
This file may look like this: #include "../GaussSeidel.h" #include <boost/test/unit_test.hpp> #include <boost/test/floating_point_comparison.hpp> BOOST_AUTO_TEST_SUITE( Gau?_Seidel_iteration_test_suite ) BOOST_AUTO_TEST_CASE( GaussSeidelTest4 ) { DenseMatrix A(3, 3); Vektor x(3); Vektor y(3); GaussSeidel gs1("damped Gau?-Seidel (SOR)", 0.5, 1); // 1 iteration gs1.solve(A, x ,y); BOOST_CHECK_CLOSE(X[0], -108.0/240, 1E-10); BOOST_CHECK_CLOSE(X[1], -27.0/240, 1E-10); BOOST_CHECK_CLOSE(X[2], 38.0/240, 1E-10); } BOOST_AUTO_TEST_SUITE_END() Don't you think this look a bit neater? And it works both with static and shared library. All you need is to define BOOST_TEST_DYN_LINK in makefile during compilation to be able to link with shared library. And this works for both *nix and NT. Gennadiy

On Sat, 05 Jan 2008 09:00:47 +0100, Gennadiy Rozental <rogeeff@gmail.com> wrote: [...] This file may look like this: [..] Gennadiy, Jans example was exactly what I was looking for. It's a nice example how to build many-files suites. Maybe include that in your example pages. Thanks for your help Jans and Gennadiy. Greetings, Tomasz

Tomasz Kalkosiński <pppsp <at> gazeta.pl> writes:
On Sat, 05 Jan 2008 09:00:47 +0100, Gennadiy Rozental <rogeeff <at>
gmail.com>
wrote:
[...] This file may look like this: [..]
Gennadiy, Jans example was exactly what I was looking for. It's a nice example how to build many-files suites. Maybe include that in your example pages.
It's up to you, but I would give automated registration a try. Gennadiy

"Tomasz Kalkosinski" <pppsp@gazeta.pl> wrote in message news:op.t4fkq0mq2fp26v@localhost...
On Wed, 02 Jan 2008 04:57:28 +0100, Gennadiy Rozental <rogeeff@gmail.com> wrote:
Why don't you post specific problems with faling test modules examples.
My problem is easy. I want to have one main test that add Second and so on. I cannot get it to work :/ What's the best practice?
What you describe is unclear to me. Do you intend to add new test cases at runtime while test module is working? Or you just need more than one test case? Or do you need complex hierarhy?
Is BOOST_CLASS_TEST_CASE a good approach on Second? I cannot get add to work
I can't give 100%, since your intent is unclear to me, but I don;t think BOOST_CLASS_TEST_CASE has anything to do with it.
:/ I definitely need an example with two file, parent and child test example.
What do you mean by parent-child relationship here?
Thanks in advance, Tomasz Kalkosinski
Gennadiy
participants (3)
-
Gennadiy Rozental
-
Jens Seidel
-
Tomasz Kalkosiński