Boost logo

Boost Users :

From: Anders Moe (yg-boost-users_at_[hidden])
Date: 2003-09-01 01:52:36


>> If I understand you correctly you suggest using the ctor/dtor in the
>> class-test-case to do the job of build_up/tear_down. I suppose that
> would be
>> equivalent to setup/teardown. This works, ofcourse, because a C++
>> programmer can rely on the dtor being executed, unlike the Java
> finalizer.
>>
>> Anders.
>
> Does that mean that my answer sattisfy your need in bringup/teardown
> functionality? Do you think it is going to be acceptable always?
>

Having given some thought to this during the weekend I have also realized a
significant difference between ctor/dtor and setup/teardown, as was posted
in another subthread of this thread, namely this :

1) the ctor(s) is called at test _setup_ time, while the setup(s) is called
at test _runtime_
2) the dtor(s) is called at test suite exit time, while the teardown(s) is
called, again, at test runtime.

This makes a real difference when, say, setup acquires a unique resource :

boost_shared_ptr<Test1> (new Test1); // ctor called, open log file log.txt
suite->add_test_case (<some Test1 method)
suite->add_test_case (<some Test1 method)
suite->add_test_case (<some Test1 method)

boost_shared_ptr<Test1> (new Test2); // ctor called, open log file
log.txt...FAILURE, already open
suite->add_test_case (<some Test2 method)
suite->add_test_case (<some Test2 method)
suite->add_test_case (<some Test2 method)

If instead log.txt was opened/closed in setup/teardown, the test methods
called in between would work just fine.

Anders Moe.


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