#include<iostream>#include<gtest/gtest.h>intAdd(int x,int y){return x + y;}TEST(Plus_Test, Equal){ASSERT_EQ(Add(10,10),20);}TEST(ERROR_TEST, NE){ASSERT_EQ(Add(10,10),30);}TEST(EXPECT_TEXT, EXPECT){EXPECT_LT(Add(20,20),10);
std::cout <<"Output in EXPECT_TEST, but after EXPECT_LT"<< std::endl;ASSERT_EQ(Add(10,10),30);
std::cout <<"Output in EXPECT_TEST"<< std::endl;}intmain(int argc,char* argv[]){// Init Test Module
testing::InitGoogleTest(&argc, argv);// Invokle all testsreturnRUN_ALL_TESTS();}
$ ./main
[==========] Running 3 tests from 3 test suites.
[----------] Global test environment set-up.
[----------] 1 test from Plus_Test
[ RUN ] Plus_Test.Equal
[ OK ] Plus_Test.Equal (0 ms)
[----------] 1 test from Plus_Test (0 ms total)
[----------] 1 test from ERROR_TEST
[ RUN ] ERROR_TEST.NE
main.cc:16: Failure
Expected equality of these values:
Add(10, 10)
Which is: 20
30
[ FAILED ] ERROR_TEST.NE (0 ms)
[----------] 1 test from ERROR_TEST (0 ms total)
[----------] 1 test from EXPECT_TEXT
[ RUN ] EXPECT_TEXT.EXPECT
main.cc:21: Failure
Expected: (Add(20, 20)) < (10), actual: 40 vs 10
Output in EXPECT_TEST, but after EXPECT_LT
main.cc:25: Failure
Expected equality of these values:
Add(10, 10)
Which is: 20
30
[ FAILED ] EXPECT_TEXT.EXPECT (0 ms)
[----------] 1 test from EXPECT_TEXT (0 ms total)
[----------] Global test environment tear-down
[==========] 3 tests from 3 test suites ran. (0 ms total)
[ PASSED ] 1 test.
[ FAILED ] 2 tests, listed below:
[ FAILED ] ERROR_TEST.NE
[ FAILED ] EXPECT_TEXT.EXPECT
2 FAILED TESTS