Installing Google Test
I will show you how to run Google Test on Linux. If you're not sure how to set up Linux on Windows, refer to the WSL2 setup guide.
First, install the necessary packages.
package | use |
---|---|
build-essential | Used for building C and C++ |
cmake | Used for building projects |
lcov | Tool for displaying test coverage |
On Ubuntu, you can install them with the following commands. Adjust the commands as needed depending on your Linux distribution.
sudo apt install build-essential
sudo apt install lcov
sudo apt install cmake
Installing GoogleTest
A package for GoogleTest, libgtest-dev
, exists, but older versions do not include Google Mock. Therefore, it's recommended to clone the repository and build the source code directly.
Clone the source code:
git clone https://github.com/google/googletest.git
cd googletest
Create a build directory:
mkdir build
cd build
Build using CMake:
cmake ..
make
Install the libraries into your system:
sudo make install
This will place the build binary libgmock.a
, libgmock_main.a
, libgtest.a
, and libgtest_main.a
in the /usr/local/lib folder, making GoogleTest and GoogleMock available for use.