[test] Confused about stuff...

Hey guys, I'm currently in the process of researching Boost.Test. I've never used it before, and reading through the documentation for it and the various examples, I have a few questions I can't find the answers to. I'll post them below: 1. init_unit_test_suite is used fairly exclusively through the examples. The most I can gather is that this function begins the unit test. In other words, it calls other smaller functions which perform tests. How is this function evoked? 2. What is the difference in using init_unit_test_suite versus using #define BOOST_TEST_MAIN? 3. When creating a unit test as a console application in Visual Studio, I would of course be required to implement the normal int main() function, but what would I have to do inside of main() or WinMain() to begin the unit test? I never found any examples that showed this. If I think of more questions I'll be sure to post follow ups. Help is greatly appreciated. Thanks in advance!

Robert Dailey
Hey guys,I'm currently in the process of researching Boost.Test. I've never
used it before, and reading through the documentation for it and the various examples, I have a few questions I can't find the answers to. I'll post them below: ut Stop right there. Docs are very outdated. Use beta on: patmedia.net/~rogeeff/hmtl/index.html
init_unit_test_suite is used fairly exclusively through the examples. The
most I can gather is that this function begins the unit test. In other words, it calls other smaller functions which perform tests. How is this function evoked? No. It does not.
What is the difference in using init_unit_test_suite versus using #define BOOST_TEST_MAIN?
Errrh. This question doesn't make much sense really. But you can blame me again.
When creating a unit test as a console application in Visual Studio, I would of course be required to implement the normal int main() function,
No. you don't.
but what would I have to do inside of main() or WinMain() to begin the unit test? I never found any examples that showed this. If I think of more questions I'll be sure to post follow ups. Help is greatly appreciated. Thanks in advance!
Please read proper docs. Hopefully they'll shed some light. Regards, Gennadiy

Gennadiy Rozental wrote:
Robert Dailey
writes: Hey guys,I'm currently in the process of researching Boost.Test. I've never
used it before, and reading through the documentation for it and the various examples, I have a few questions I can't find the answers to. I'll post them below: ut Stop right there. Docs are very outdated. Use beta on:
patmedia.net/~rogeeff/hmtl/index.html
Is there some weird reason these aren't on the site? -- Sohail Somani http://uint32t.blogspot.com

Please see my answers below.
On Thu, May 1, 2008 at 9:33 PM, Robert Dailey
Hey guys,
I'm currently in the process of researching Boost.Test. I've never used it before, and reading through the documentation for it and the various examples, I have a few questions I can't find the answers to. I'll post them below:
1. init_unit_test_suite is used fairly exclusively through the examples. The most I can gather is that this function begins the unit test. In other words, it calls other smaller functions which perform tests. How is this function evoked?
This function is invoked by the unit test framework internally.
1. 2. What is the difference in using init_unit_test_suite versus using #define BOOST_TEST_MAIN?
Using init_unit_test_suite you have to manually register all your test
cases to be excuted. Using BOOST_TEST_MAIN and BOOST_TEST_CASE (or whatever was the name of the macro) the framework will handle it for you. You just write test cases and are no longer required to care about main() and test case registration.
1. 2. When creating a unit test as a console application in Visual Studio, I would of course be required to implement the normal int main() function, but what would I have to do inside of main() or WinMain() to begin the unit test? I never found any examples that showed this.
As already stated these function are implemented by the test framework
which links with your code and compiler finds them. The main drawback using
init_unit_test_suite is when you are not allowed to use a static version of
the boost test lib, so that DLL links to your code. In this case main and so
on are required to be implemented by you, where in case of BOOST_TEST_MAIN
it is automatically generated by the macro.
I initially used init_unit_test_suite to be able to create test hierarchies
but after switching to the dynamic boost lib (due to project requirements) I
was forced to reimplement the init_unit_test_suite. It was not difficult,
but I had to find how to do it, which was not easy.
This is the code I used:
Initialize BOOST Unit Test, when it is used as DLL and custom main function
is required
#include
1.
If I think of more questions I'll be sure to post follow ups. Help is greatly appreciated. Thanks in advance!
Hope that helps, Ovanes

On Thu, May 1, 2008 at 3:59 PM, Ovanes Markarian
Please see my answers below.
On Thu, May 1, 2008 at 9:33 PM, Robert Dailey
wrote: Hey guys,
I'm currently in the process of researching Boost.Test. I've never used it before, and reading through the documentation for it and the various examples, I have a few questions I can't find the answers to. I'll post them below:
1. init_unit_test_suite is used fairly exclusively through the examples. The most I can gather is that this function begins the unit test. In other words, it calls other smaller functions which perform tests. How is this function evoked?
This function is invoked by the unit test framework internally.
1. 2. What is the difference in using init_unit_test_suite versus using #define BOOST_TEST_MAIN?
Using init_unit_test_suite you have to manually register all your test
cases to be excuted. Using BOOST_TEST_MAIN and BOOST_TEST_CASE (or whatever was the name of the macro) the framework will handle it for you. You just write test cases and are no longer required to care about main() and test case registration.
1. 2. When creating a unit test as a console application in Visual Studio, I would of course be required to implement the normal int main() function, but what would I have to do inside of main() or WinMain() to begin the unit test? I never found any examples that showed this.
As already stated these function are implemented by the test framework
which links with your code and compiler finds them. The main drawback using init_unit_test_suite is when you are not allowed to use a static version of the boost test lib, so that DLL links to your code. In this case main and so on are required to be implemented by you, where in case of BOOST_TEST_MAIN it is automatically generated by the macro.
I initially used init_unit_test_suite to be able to create test hierarchies but after switching to the dynamic boost lib (due to project requirements) I was forced to reimplement the init_unit_test_suite. It was not difficult, but I had to find how to do it, which was not easy.
This is the code I used:
<snip>
1.
If I think of more questions I'll be sure to post follow ups. Help is greatly appreciated. Thanks in advance!
Hope that helps, Ovanes
@Ovanes: Thanks for your help. Right now I'm building the entire boost library as shared libraries. Is there a way I can specifically make bjam build the Boost.Test framework as a static library? If it saves me a lot of trouble I'd rather it be a static library. I'm not very good with bjam so if someone could tell me how to make Boost.Test build statically I'd appreciate it.

@Ovanes:
Thanks for your help. Right now I'm building the entire boost library as shared libraries. Is there a way I can specifically make bjam build the Boost.Test framework as a static library? If it saves me a lot of trouble I'd rather it be a static library. I'm not very good with bjam so if someone could tell me how to make Boost.Test build statically I'd appreciate it.
AFAIK bjam builds dynamic and static versions. When using Visual C++ boost
will automatically link with the proper version, dependent on your project setting in VC or issue errors compilation error that you mix incompatible versions. Try starting with BOOST_AUTO_TEST_CASE and BOOST_TEST_MAIN and see if you need more complex unit tests or can handle everything with the macro based test cases. Actually you can also use with macro based version of Unit Test Framework as DLL without any problems Good Luck, Ovanes
participants (4)
-
Gennadiy Rozental
-
Ovanes Markarian
-
Robert Dailey
-
Sohail Somani