Skip to content

Conversation

@kazurem
Copy link
Collaborator

@kazurem kazurem commented Dec 9, 2025

1. Using CMake's FetchContent Module, automated the fetch and build of GoogleTest.

# This block executes only if the user configures CMake with -DBUILD_TESTING=ON.
if(BUILD_TESTING)
    include(FetchContent)
    FetchContent_Declare(
        googletest
        GIT_REPOSITORY https://github.com/google/googletest.git
        # Use a specific stable commit or tag (like release-1.14.0) for reliability.
        GIT_TAG        52eb8108c5bdec04579160ae17225d66034bd723
        # Recommended: Add DOWNLOAD_EXTRACT_TIMESTAMP TRUE for build robustness (CMP0135).
    )

    # Makes the googletest targets (GTest::gtest, GTest::gtest_main, etc.) available 
    # for linking in subsequent targets (like mms-test).
    FetchContent_MakeAvailable(googletest)
endif()

2. Created a tests folder which will contain all the test files:

The CMakeLists.txt for the tests folder is:

# the test executable and related targets are only built when the user configures CMake with 
# -DBUILD_TESTING=ON (as defined in the root CMakeLists.txt and CTest module).
if(BUILD_TESTING)

    # Creates the binary file (e.g., mms-test.exe) that will run all unit tests.
    add_executable(mms-test MazeGen-Test.cpp)

    # Connects the test executable to the necessary compiled code.
    target_link_libraries(mms-test 
        PRIVATE 
            # Links to the GoogleTest main library, which provides the main() function 
            # to run the tests and the testing framework itself.
            GTest::gtest_main 

            # Links to your project's core logic library (defined in the root CMakeLists.txt).
            # This is essential for calling the functions that we want test.
            mms-core
    )

    # Includes GoogleTest-specific CMake macros. This is necessary for gtest_discover_tests.
    include(GoogleTest)

    # Searches the compiled executable (mms-test) for all defined tests (using TEST/TEST_F macros)
    # and registers them with CTest. This allows you to run tests using the 'ctest' command.
    gtest_discover_tests(mms-test)

endif()

3. Added a basic test to check if GTest is working fine or not:

//MazeGen.cpp
size_t MazeGen::exampleFunc() { return 42; }
//MazeGen-Test.cpp
#include "MazeGen.hpp"
#include <gtest/gtest.h>

TEST(TestTopic, TrivialEquality) { EXPECT_EQ(MazeGen::exampleFunc(), 42); }

@kazurem kazurem linked an issue Dec 9, 2025 that may be closed by this pull request
@kazurem kazurem merged commit cb063c0 into kr8457:dev Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setup testing using GoogleTest Framework.

1 participant