[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 <rcdailey <at> gmail.com> 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
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.
Please read proper docs. Hopefully they'll shed some light. Regards, Gennadiy

Gennadiy Rozental wrote:
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 <rcdailey@gmail.com> wrote:
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.
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 <boost/test/unit_test.hpp> #include <boost/shared_ptr.hpp> #include <boost/ref.hpp> // create this post-build event //Autorun Unit Tests //"$(TargetDir)\$(TargetName).exe" --result_code=no --report_level=no namespace ut=boost::unit_test; bool *init_test_suite*() { using namespace boost; using namespace ut; master_test_suite_t& master=framework::master_test_suite(); test_suite* test= BOOST_TEST_SUITE( "Testing configuration parameter library" ); master.add(test); test_suite* plaf = BOOST_TEST_SUITE( "Testing Platform Services implementation" ); test->add(plaf); shared_ptr<plaf_svc_test> platform_tc( new plaf_svc_test(master.argv[0]) ); plaf->add( BOOST_CLASS_TEST_CASE(&plaf_svc_test::test_name, platform_tc) ); plaf->add( BOOST_CLASS_TEST_CASE(&plaf_svc_test::test_path, platform_tc) ); test_suite* conf_gen = BOOST_TEST_SUITE( "Testing Configuration File generation" ); test->add(conf_gen); shared_ptr<config_gen_tests> cfg_tc( new config_gen_tests ); conf_gen->add( BOOST_CLASS_TEST_CASE(&config_gen_tests::test_generated_types, cfg_tc) ); conf_gen->add( BOOST_CLASS_TEST_CASE(&config_gen_tests::test_valid_names, cfg_tc) ); conf_gen->add( BOOST_CLASS_TEST_CASE(&config_gen_tests::test_invalid_names, cfg_tc) ); test_suite* parsing = BOOST_TEST_SUITE( "Config File Parsing Related Tests" ); test->add(parsing); parsing->add(BOOST_TEST_CASE(&cfg_parsing_tests::start_tests)); return true; } int main(int argc, char* argv[]) { return ::boost::unit_test::*unit_test_main*(&*init_test_suite*, argc, argv); }

On Thu, May 1, 2008 at 3:59 PM, Ovanes Markarian <om_boost@keywallet.com> wrote:
<snip>
@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.

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