As Real Fresh suggested to use vcpkg mananger https://github.com/microsoft/vcpkg
And So I gave it a try, I faced couple of issues but after that It worked so what I did is:
1.install vcpkg https://github.com/microsoft/vcpkg (Follow the instructions)
You migh have the error when setting up (Fatal error, could not do post-extract operation renaming 'File' to 'Different name' ) You need to rename the manually.
2.install boost-test lib (you will see instruction on how to install packages) on the home page of vcpkg
3.you need to set these variables for cmake:
-DVCPKG_TARGET_TRIPLET=x86-windows (x86-windows in my case)
"-DCMAKE_TOOLCHAIN_FILE='root to vcpkg'/scripts/buildsystems/vcpkg.cmake" (in my case root to vcpkg = F:/Files/vcpkg
so the variable will be:
"-DCMAKE_TOOLCHAIN_FILE=F:/Files/vcpkg/scripts/buildsystems/vcpkg.cmake"
4.in your test/cmakelists.txt file you need to add the following:
find_package (Boost REQUIRED COMPONENTS unit_test_framework)
target_link_libraries (your_test_exe Boost::unit_test_framework)
in my case I have my test/cmakelists.txt like this:
cmake_minimum_required(VERSION 3.15)
project(My_String)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "--coverage" )
set(SOURCE_FILES MyStringTest.cpp)
set(Boost_DEBUG ON)
find_package (Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(../Src)
add_executable (Boost_Tests_run ${SOURCE_FILES})
target_link_libraries (Boost_Tests_run Boost::unit_test_framework)
5.In your test.cpp you need to include:
#include <boost/test/included/unit_test.hpp> as it is!
in addition to the classes you are testing.
in my case it looks like this:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE MyString_Test_Suite
#include
#include "MyString.h"
#include "MyString.cpp"
#include <boost/test/included/unit_test.hpp>
After more than a week of googling, trial and error this finally worked for me!
Hope it helps if any one face the same issue.
Thank you Real Fresh for your support!