Writing some simple tests
Our first task is to set up CMake for adding tests. This includes finding the Google Test library and the CMake support functions by adding the following lines to the root CMakeLists.txt:
find_package(GTest CONFIG REQUIRED)
include(GoogleTest)
Now we can link the GTest::gtest_main library to our test executables and the gtest_discover_tests function to register the tests contained therein to the CTest harness. (This makes actually running all the tests in a project very easy.) The next task is to create a new executable target in the readers/CMakeLists.txt file and register the tests. The code is as follows:
add_executable(test_ducky_readers
test_csv_reader.cpp
test_json_reader.cpp
)
target_link_libraries(test_ducky_readers PRIVATE
ducky_readers
spdlog::spdlog
GTest::gtest_main
)
gtest_discover_tests(test_ducky_readers)
We’ve already added the two test source files, though we have yet to create them. As the names...