add testing infrastructure

This commit is contained in:
2026-05-06 23:05:14 -05:00
parent dc7ebdbb73
commit 35cc73b04f
6 changed files with 104 additions and 3 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
build/* build/*
Testing/*

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.23)
project(maiden) project(maiden)
@@ -8,18 +8,40 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
# gtest
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.17.x # Use a specific version tag or commit hash
)
FetchContent_MakeAvailable(googletest)
# add_subdirectory() to nest CMakeLists # add_subdirectory() to nest CMakeLists
add_executable(maiden add_executable(maiden
src/App.cpp
src/main.cpp src/main.cpp
# include extra source files here # include extra source files here
) )
add_executable(maiden_test
src/App.cpp
test/TestApp.cpp
)
target_include_directories(maiden PRIVATE target_include_directories(maiden PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src"
# add additional include directories here # add additional include directories here
) )
target_link_libraries(maiden PRIVATE target_include_directories(maiden_test PRIVATE
# add libraries here "${CMAKE_CURRENT_SOURCE_DIR}/src"
) )
target_link_libraries(maiden_test PRIVATE
GTest::gmock_main
)
include(GoogleTest)
gtest_discover_tests(maiden_test)

18
src/App.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "App.hpp"
void App::run() {
std::cout << "im an app and im running !!" << std::endl;
(void)foo();
return;
}
int32_t App::foo() {
return 12;
}

19
src/App.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <iostream>
#include <cstdint>
class App {
public:
App() = default;
~App() = default;
void run();
private:
int32_t foo();
};

View File

@@ -1,9 +1,14 @@
#include <iostream> #include <iostream>
#include "App.hpp"
int main(int argc, char** argv) { int main(int argc, char** argv) {
std::cout << "hi mom !" << std::endl; std::cout << "hi mom !" << std::endl;
App app;
app.run();
return 0; return 0;
} }

36
test/TestApp.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <gmock/gmock.h>
#include <memory>
#define private public
#include <App.hpp>
#undef private
class TestApp : public testing::Test {
protected:
void createUut() {
uut_ = std::make_unique<App>();
}
std::unique_ptr<App> uut_;
};
TEST_F(TestApp, TestApp_run_nominal) {
createUut();
uut_->run();
// no expect here
}
TEST_F(TestApp, TestApp_foo_nominal) {
createUut();
EXPECT_EQ(uut_->foo(), 12);
}