C++ Unit Tests — 1

TEST(myTests, addTwoNumReturnsInt)
{
int result {0}; // Arrange
result = addTwoNum(10, 22); // Act GTEST_ASSERT_EQ(result, 32); // Assert
}
cmake_minimum_required(VERSION 3.12)     # Requiredproject(my_cpp_project)                  # Requiredadd_subdirectory(googletest)             # googletest subdirectoryinclude_directories(googletest/include) add_executable(medium medium.cpp)        # Requiredtarget_link_libraries(medium PRIVATE gtest)    # Required for googletest
#include <gtest/gtest.h>int addTwoNum(int x,int y){
return x+y;
}
TEST(myTests, addTwoNumReturnsInt)
{
int result {0};
result = addTwoNum(10, 22);
GTEST_ASSERT_EQ(result, 32);
}
int main(int argc, char* argv[]){ ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

--

--

--

DevOps who is willing to learn and try new things.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

IDFC Share Tips for Oct 19, 2012

TurboTrix Finance Airdrop

Vocational Books That I Read and Going to Read.

Weekly Recap #2

My first CLI Ruby gem

Xamarin.Forms How to: Integrate Android 7.1 App Shortcuts

Ruby Weekly Issue 8

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sachith Muhandiram

Sachith Muhandiram

DevOps who is willing to learn and try new things.

More from Medium

In C++, write a method that compute squares using pointers

Idiomatic Event Loop in C++

Object Oriented Programming in C++ 101 (A practical Approach)

Move-in-move-out in C++