https://github.com/prophetru/privateunittest
The project demonstrates unit-testing of private methods
https://github.com/prophetru/privateunittest
cpp gtest private unit-test
Last synced: 4 months ago
JSON representation
The project demonstrates unit-testing of private methods
- Host: GitHub
- URL: https://github.com/prophetru/privateunittest
- Owner: ProphetRu
- License: apache-2.0
- Created: 2025-03-15T12:09:29.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2025-03-15T12:29:07.000Z (10 months ago)
- Last Synced: 2025-03-15T13:23:27.682Z (10 months ago)
- Topics: cpp, gtest, private, unit-test
- Language: CMake
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Private Unit Test
PrivateUnitTest - The project demonstrates unit-testing of private methods.
## Dependencies
* [googletest](https://github.com/google/googletest)
## How to use
### In project
For the class under test, add an include only for the test mode:
```cpp
#ifdef UNIT_TESTING
#include
#endif // UNIT_TESTING
```
Inside the class under test, add a macro for test mode only:
```cpp
#ifdef UNIT_TESTING
FRIEND_TEST(test_case_name, test_name);
#endif // UNIT_TESTING
```
### In test
Include the testing class with test macro:
```cpp
#define UNIT_TESTING
#include "TestClass.h"
#include "TestClass.cpp" // the linking error without this #include
#undef UNIT_TESTING
```
Add unit-test:
```cpp
TEST(test_case_name, test_name)
{
// here you can access to private methods of the class under test
}
```
## Build local Windows/Linux
```shell
vcpkg install gtest
vcpkg integrate install
cd PrivateUnitTest
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE="path/to/vcpkg/scripts/buildsystems/vcpkg.cmake"
cmake --build . --config Release
```
## Testing
```shell
ctest
```