/cpp-googletest

Writing unittest for C++ using googletest framework.

Primary LanguageC++

Testing C++ Code using GoogleTest Framework

Knowing how to write proper unittest is crucial in writing good code. C++ Testing might look overwhelming to some people especially people who are new to coding. This code snippet will help those people start writing unittests for their applications.

For an in-depth sample code and examples you can check Google Test Sample Code

Installation

Linux/Ubuntu/Debian based

Install dependencies

sudo apt-get install libgtest-dev
sudo apt-get install cmake

Build googletest

cd /usr/src/googletest/googletest
sudo mkdir build
cd build
sudo cmake ..
sudo make
sudo cp lib/libgtest* /usr/lib
cd ..
sudo rm -rf build

Make symlinks

sudo mkdir /usr/local/lib/googletest
sudo ln -s /usr/lib/libgtest.a /usr/local/lib/googletest
sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/googletest

Execute

mkdir build
cd build
cmake ..
make
./runTests

For explanation of testing refer the code

Visual Studio Code Extension

If you use vscode you may use this extension which shows test in vscode itself.

C++ TestMate
Id matepek.vscode-catch2-test-adapter
Publisher Mate Pek

Links

GoogleTest github

Google Test Primer

Setup and Install

Google Test intro by IBM

Getting started on ubuntu

Google Mock (I'll cover this in the future)