Skip to content

Commit 783d672

Browse files
committed
test(GoogleTest): Add sample GoogleTest tests
Reference: https://google.github.io/googletest/quickstart-cmake.html#create-and-run-a-binary
1 parent c783cc6 commit 783d672

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ FetchContent_Declare(
1818
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
1919
FetchContent_MakeAvailable(googletest)
2020

21+
# Reference: https://google.github.io/googletest/quickstart-cmake.html#create-and-run-a-binary
22+
enable_testing()
23+
24+
add_executable(
25+
hello_test
26+
hello_test.cc
27+
)
28+
target_link_libraries(
29+
hello_test
30+
GTest::gtest_main
31+
)
32+
33+
include(GoogleTest)
34+
gtest_discover_tests(hello_test)
35+
2136
# END - For setting up Google Test
2237
###
2338

hello_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <gtest/gtest.h>
2+
3+
// Demonstrate some basic assertions.
4+
TEST(HelloTest, BasicAssertions) {
5+
// Expect two strings not to be equal.
6+
EXPECT_STRNE("hello", "world");
7+
// Expect equality.
8+
EXPECT_EQ(7 * 6, 42);
9+
}

0 commit comments

Comments
 (0)