安装步骤:
sudo dnf install dnf-plugins-core
sudo dnf config-manager --set-enabled PowerTools
sudo dnf install gtest gtest-devel
上述命令成功后,系统里可以看到gtest.h
了:
$ sudo find /usr -name gtest.h
/usr/include/gtest/gtest.h
/usr/include/gtest/internal/custom/gtest.h
- 例子1 -
$ cat a.cpp
int add(int a, int b)
{
return a + b;
}
$ cat a_test.cpp
#include <gtest/gtest.h>
int add(int a, int b);
TEST(TestACPP, add_ok)
{
ASSERT_EQ(3, add(1,2));
ASSERT_EQ(30000, add(10000,20000));
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
image.png
- 常用的宏 -
ASSERT_EQ 失败了即停止
EXPECT_EQ 失败了仍继续
网友评论