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
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
mkdir build
cd build
cmake ..
make
./runTests
For explanation of testing refer the code
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 |