I am using CLion on mac os mohave. I tried to add Boost.TEST to my c++ project, but the IDE throws "Test framework quit unexpectedly".
Here is my CMakeLists:
cmake_minimum_required(VERSION 3.12)
project(sequences)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
add_executable(sequences main.cpp)
target_link_libraries(sequences ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
enable_testing()
And a simple test:
#include <iostream>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test) {
BOOST_CHECK_EQUAL(1, 1);
}
using namespace std;
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Instructions on jetbrains website are bogus about using Boost.TEST and all fixes for this issue I found online are outdated.
I use Boost v.1.67.0 installed with homebrew.
Console output:
Testing started at 09:48 ... .../sequences --run_test=test --logger=HRF,all --color_output=false --report_format=HRF --show_progress=no Hello, World! Process finished with exit code 0
All help and advice are appreciated!
Thanks for help. I ended up creating a template project for tests. I then copy this project into my the project with the actual code and add add_subdirectory(name_of_the_directory_with_boost_test_project) into CMakeFile.
After that you get the "run all test" functionality in CLion.
Your program code and your test code should be separated. As stated in doc, the line
creates the main entry point.
I don't know if it is possible to write test cases in main.cpp. In unit tests you check the interface of your components.
CMakeLists.txt:
main.cpp
MyMath.h:
test1.cpp:
Now I can build it with cmake and test with ctest.