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

(Cordic Algorithm)

The state of university and college content management systems in 2021

Swift Refactoring — Tests

tAPIr’s Endpoint meets ZIO’s IO

Install Ubuntu alongside Windows

Introduction To Buffer Overflows from absolute beginning

Integration Testing with WireMock

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

Singleton Design with Multithreading in C++

String Compression

Coding with Java Optionals.

C++ fluent builder pattern