I'm new to both vcpkg and boost library and I've been researching, and trying, how to setup boost-unit-tests-framework on VS 2019 but all docs seem out of date.
My goal is to run boost tests from test explorer in visual studio.
Vcpkg
- Cloned Vcpkg and ran bootstrap-vcpkg.bat
- Ran vcpkg integrate install to configure Visual Studio with the library and include paths of the installed packages
Compiling tests [Debug only]
Following: ms-docs
- Installed boost-test package using
vcpkg install boost-test:x64-windows-static
- Added the following elements to the
<PropertyGroup Label="Globals">
in my unit test project:
<VcpkgTriplet>x64-windows-static</VcpkgTriplet>
<VcpkgEnabled>true</VcpkgEnabled>
- Set C/C++ -> Code Generation -> Runtime Library to
Multi-threaded Debug (/MTd)
- Added Additional include directories ->
$(VcpkgRoot)include\
that resolves toC:\vcpkg\installed\x64-windows-static\include\
- Added Linker -> Additional Library Directories ->
$(VcpkgRoot)debug\lib\
that resolves toC:\vcpkg\installed\x64-windows-static\debug\lib\
- Added Linker -> Input -> Additional Dependencies ->
boost_unit_test_framework-vc140-mt-gd.lib;boost_regex-vc140-mt-gd.lib;boost_exception-vc140-mt-gd.lib;boost_container-vc140-mt-gd.lib;%(AdditionalDependencies)
- Added test code:
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp>
#include <string>
class MyClass
{
std::string m_name = "Jim";
public:
std::string get_value() const { return m_name; }
void set_value(std::string const &name) { m_name = name; }
};
BOOST_AUTO_TEST_CASE(my_boost_test)
{
std::string expected_value = "Bill";
MyClass mc;
BOOST_CHECK(expected_value == mc.get_value());
BOOST_TEST(expected_value == mc.get_value());
mc.set_value(expected_value);
BOOST_TEST(expected_value == mc.get_value());
}
Console run
Everything runs fine running the test exe from console:
VS Test explorer
Nothing shows up on the test-explorer, even if my boost test-adapter is intalled..
Has anyone solved this yet??
One alternative I've found is to run the test.exe as part of the build process like boost-docs mention. Not quite as useful for my team.