#include<gtest/gtest.h>// function for which we write unit testsintadd(intnum1,intnum2){returnnum1+num2;}// to test addition of positive numbersTEST(SumTest,ForPositiveNumbers){EXPECT_EQ(35,add(23,12));}// to test addition of negative numbersTEST(SumTest,ForNegativeNumbers){EXPECT_EQ(-1,add(-1,0));}
cmake_minimum_required(VERSION3.22)# Project setupproject(DemoAppVERSION0.1.0LANGUAGESCXX)# Require GoogleTestfind_package(GTestREQUIRED)include(GoogleTest)enable_testing()# defining executable target and its source fileadd_executable(test_demotest/test_demo.cpp)# to link the executable with GoogleTest main librarytarget_link_libraries(test_demoGTest::gtest_main)# to discover and register all tests in the executablegtest_discover_tests(test_demo)