Unit Tests
Unit tests are the first level of testing within the software development lifecycle.
In this project, they are firstly used by the developer to ensure the code they produce is working on a component
level and in second hand, they are used in the CI-CD pipeline to ensure nothing was broken before merging new codes into
another branch.
GoogleTest is used as the testing framework and is directly retrieved
from FetchContent when the appropriate cmake option
is given.
Architecture
- The tests folder comes next to the component to be tested ;
- Sources containing test code must follow this pattern:
[FileNameToBeTested]Tests.cpp
For exemple:
core
├── CMakeLists.txt
├── CoreApplication.cpp
├── include
│ └── core
│ ├── CoreApplication.h
│ └── Logger.h
├── Logger.cpp
└── tests
├── CMakeLists.txt
├── CoreApplicationTests.cpp
└── LoggerTests.cpp
will be the test folder architecture for the component named core
CMakeLists.txt example
##
## CMakeLists.txt
## Copyright (C) Witekio. All rights reserved.
## Reproduction, copy, modification in whole or part is prohibited
## without the written permission of the copyright owner.
##
set(TARGET_NAME test[ComponentName])
add_executable(${TARGET_NAME})
target_sources(${TARGET_NAME} PRIVATE
# sources..
)
target_link_libraries(${TARGET_NAME}
# dependencies
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(${TARGET_NAME})