Boost.Test: File/build structure for Boost.Test unit

Hi, I'm using Boost.Test for unit testing a project I am working on. My question is if there is a standard way to set up and structure your unit test project. I am using Eclipse/CDT on Linux and my project is an executable shell script daemon with a bunch of classes compiled and linked into it. In order to unit test the various classes I set up another project, specifically for unit tests that compiles and links in all the classes from the main project. Now, my question is this: do I have one monolithic unittests.cpp file that for all the unit tests or should I set up multiple files which is preferable, e.g. one cpp file per class being tested. Is there a standard "best practices" way to do this? Best Regards, Ari Johannesson

This probably belongs on the users list, but I think you treat tests as the same way you treat your code. Would you have all your code in one file? I usually split up my tests the same way I split up my code. So the structure might look like: lib1/ tests/ test_a.cpp test_b.cpp src/ a.cpp b.cpp lib2/ tests/ ... src/ ... I would then compile all of one directory's tests into an executable. -----Original Message----- From: boost-bounces@lists.boost.org on behalf of Ari Johannesson Sent: Sat 4/7/2007 9:41 AM To: boost@lists.boost.org Subject: [boost] Boost.Test: File/build structure for Boost.Test unit Now, my question is this: do I have one monolithic unittests.cpp file that for all the unit tests or should I set up multiple files which is preferable, e.g. one cpp file per class being tested.

"Ari Johannesson" <ari@marimo.is> wrote in message news:4617C9CD.5070305@marimo.is...
Hi,
I'm using Boost.Test for unit testing a project I am working on. My question is if there is a standard way to set up and structure your unit test project.
I am using Eclipse/CDT on Linux and my project is an executable shell script daemon with a bunch of classes compiled and linked into it.
In order to unit test the various classes I set up another project, specifically for unit tests that compiles and links in all the classes from the main project.
Now, my question is this: do I have one monolithic unittests.cpp file that for all the unit tests or should I set up multiple files which is preferable, e.g. one cpp file per class being tested.
Is there a standard "best practices" way to do this?
This is not so much Boost.Test question, but rather generic testing organization issue. There is no single definitive answer to the best approach here. In some regards it's matter of your personal preference. I personally wouldn't put everything into single test module. Hundreds test modules for each test case is also wrong direction IMO. Other than that both splitting testing into test modules and test modules into test cases is your choice. Usually tests structure reflect the development one. There are some obvious separators: don't mix performance and validity tests into same test module. Don't mix test cases that might fail to compile with the rest of the tests. Strive for your test modules runtime to be reasonably short (up to 1 sec, for example) HTH, Gennadiy

Late follow-up (I must have missed the original post)... Gennadiy Rozental writes:
"Ari Johannesson" <ari@marimo.is> wrote in message news:4617C9CD.5070305@marimo.is...
Hi,
I'm using Boost.Test for unit testing a project I am working on. My question is if there is a standard way to set up and structure your unit test project.
I am using Eclipse/CDT on Linux and my project is an executable shell script daemon with a bunch of classes compiled and linked into it.
In order to unit test the various classes I set up another project, specifically for unit tests that compiles and links in all the classes from the main project.
Now, my question is this: do I have one monolithic unittests.cpp file that for all the unit tests or should I set up multiple files which is preferable, e.g. one cpp file per class being tested.
Is there a standard "best practices" way to do this?
This is not so much Boost.Test question, but rather generic testing organization issue.
First: I agree with Gannadiy, this is a generic unit test issue. I would definitely not have one monolithic everything. I have a separate .C file with a separate test suite for, roughly, each class. My first suggestion is to do whatever Eclipse wants you to do. :-) Really: do the simplest thing that your environment will let you get away with, and that also meets your needs. The only time I've done unit testing in Java was with the "standard" unit test framework (JTest, or something?). The code lived in a directory structure under 'code'; the unit tests for the code lived in a parallel data structure under 'test', and Eclipse just Did The Right Thing. We don't use Eclipse; I'm an old Emacs guy. What we do is this: every directory containing code also contains a Test subdirectory, which contains the unit tests for that code (e.g. multiple .C files, each of which uses Gennadiy's "auto test" setup). We use Jam for our build system; we have various Jam rules for compiling and running unit tests, compiling unit test results into summaries, and so forth. Works for us. As for recommendations on how to write unit tests, the best thing I've found is NASA's Flight Code division web site, <http://software.gsfc.nasa.gov/process.cfm> ... navigate down into their testing and correctness stuff, and look for their unit testing guidelines (I can't find it at the moment, but it's in there somewhere). ---------------------------------------------------------------------- Dave Steffen, Ph.D. Fools ignore complexity. Software Engineer IV Pragmatists suffer it. Numerica Corporation Some can avoid it. ph (970) 461-2000 x227 Geniuses remove it. dgsteffen@numerica.us -- Alan Perlis ___________________ Numerica Disclaimer: This message and any attachments are intended only for the individual or entity to which the message is addressed. It is proprietary and may contain privileged information. If you are neither the intended recipient nor the agent responsible for delivering the message to the intended recipient, you are hereby notified that any review, retransmission, dissemination, or taking of any action in reliance upon, the information in this communication is strictly prohibited, and may be unlawful. If you feel you have received this communication in error, please notify us immediately by returning this Email to the sender and deleting it from your computer.
participants (4)
-
Ari Johannesson
-
Dave Steffen
-
Gennadiy Rozental
-
Sohail Somani