Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ProphetRu/PrivateUnitTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Private Unit Test

PrivateUnitTest - The project demonstrates unit-testing of private methods.

Dependencies

How to use

In project

For the class under test, add an include only for the test mode:

#ifdef UNIT_TESTING
#include <gtest/gtest_prod.h>
#endif // UNIT_TESTING

Inside the class under test, add a macro for test mode only:

#ifdef UNIT_TESTING
FRIEND_TEST(test_case_name, test_name);
#endif // UNIT_TESTING

In test

Include the testing class with test macro:

#define UNIT_TESTING
#include "TestClass.h"
#include "TestClass.cpp" // the linking error without this #include
#undef UNIT_TESTING

Add unit-test:

TEST(test_case_name, test_name)
{
// here you can access to private methods of the class under test
}

Build local Windows/Linux

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

ctest

About

The project demonstrates unit-testing of private methods

Topics

Resources

Readme

License

Apache-2.0 license

Stars

Watchers

Forks

Packages

Contributors