I am trying to implement unit test with boost test libraries. I started by reading the manual at the boost site. After this i make a simple test program in one of my already existing project. The only problem which i face is that i am unable to see the test result. I am sure that i am making some thing wrong :) but i am unable to figure that. Following are the details of my project
I am using visual studio8 for this: I have a solution named MyProject.sln
Along with other projects i have a project named MyDLL.vcproj (The type of this project is DLL)
Along with other files in MYDLL proj i add a new cpp file name MyTest.cpp, the file contains the following code:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
//#define BOOST_TEST_MODULE MyTestTestModue //no need for this maro if above macro is used
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(SampleTC)
{
BOOST_CHECK(true);
};
I make following changes in MYDLL project property sheet
C++ -> General -> Additional Include Dependencies = D:\MyProject\Boost\boost\test
Linker -> General -> Additional Libray Directories = D:\MyProject\Boost\lib\win32\Debug
Linker -> System -> SubSystem = (/SUBSYSTEM:CONSOLE)
I read all the compilation details given in the manual, but still unable to get the output. Ideally i want to use the Boost test as a standalone lib (Dynamic library varian of UTF).
Create a Boost.In the Add New Item dialog, expand Installed > Visual C++ > Test. Select Boost. Test, then choose Add to add Test. cpp to your project.
The Test Adapter for Boost. Test is a unit testing extension published by Microsoft and based on the existing Boost Unit Test Adapter (v1. 0.8) Visual Studio extension by Gunter Wirth's team from ETAS GmbH. This extension is developed in collaboration with the original project with the aim of improving Boost.
I am sure that i am making some thing wrong :)
Actually, I think the problem is you are making something right.
Your test passes, because the value checked is true
, and by default Boost.Test only outputs information about tests that have failed. You need to set the log level, which can be done one of two ways: passing --log_level=all
as an option the the test executable, or setting the environment variable BOOST_TEST_LOG_LEVEL
to all
.
See this page of the documentation for all the run time parameters.
Edit: It's actually --log_level (with an underscore in the middle)
Our unit tests are called via a tool post-compile; so we cannot easily pass a parameter to the EXE (without changing the tool configuration and affecting all tests).
So another way of setting the log-level threshold is to call the Boost unit-test logger singleton from the code:
boost::unit_test::unit_test_log_t::instance().set_threshold_level( boost::unit_test::log_messages );
For added fun, output the file name and line number where your message is displayed:
#define MY_BOOST_TEST_MESSAGE( msg ) BOOST_TEST_MESSAGE( `__FILE__` << `__LINE__` << " " << msg )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With