add testing infrastructure
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
|
||||
build/*
|
||||
Testing/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
|
||||
project(maiden)
|
||||
|
||||
@@ -8,18 +8,40 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
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_executable(maiden
|
||||
src/App.cpp
|
||||
src/main.cpp
|
||||
# include extra source files here
|
||||
)
|
||||
|
||||
add_executable(maiden_test
|
||||
src/App.cpp
|
||||
test/TestApp.cpp
|
||||
)
|
||||
|
||||
target_include_directories(maiden PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
# add additional include directories here
|
||||
)
|
||||
|
||||
target_link_libraries(maiden PRIVATE
|
||||
# add libraries here
|
||||
target_include_directories(maiden_test PRIVATE
|
||||
"${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
18
src/App.cpp
Normal 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
19
src/App.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
||||
class App {
|
||||
|
||||
public:
|
||||
App() = default;
|
||||
~App() = default;
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
|
||||
int32_t foo();
|
||||
|
||||
};
|
||||
@@ -1,9 +1,14 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "App.hpp"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
std::cout << "hi mom !" << std::endl;
|
||||
|
||||
App app;
|
||||
app.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
36
test/TestApp.cpp
Normal file
36
test/TestApp.cpp
Normal 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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user