单元测试gtest

简介

Google C++ Testing Framework(简称gtest),是Google公司发布的一个开源C/C++单元测试框架。

  • test case : 测试用例集
  • test : 测试用例
  • test fixture: 构造测试用例的公共前提条件和状态
  • test setup: 构造测试的前提脚架和状态
  • test teardown: 还原测试执行前的状态
  • assertion : 断言,用于检查

常用测试宏

以ASSERT_开头和以EXPECT_开头的宏的区别是,前者在测试失败时会给出报告并立即终止测试程序,后者在报告后继续执行测试程序。

ASSERT_TRUE(condition); 	EXPECT_TRUE(condition); 	condition is true
ASSERT_FALSE(condition); 	EXPECT_FALSE(condition); 	condition is false
ASSERT_EQ(val1,val2); 	EXPECT_EQ(val1,val2); 	val1 == val2
ASSERT_NE(val1,val2); 	EXPECT_NE(val1,val2); 	val1 != val2
ASSERT_LT(val1,val2); 	EXPECT_LT(val1,val2); 	val1 < val2
ASSERT_LE(val1,val2); 	EXPECT_LE(val1,val2); 	val1 <= val2
ASSERT_GT(val1,val2); 	EXPECT_GT(val1,val2); 	val1 > val2
ASSERT_GE(val1,val2); 	EXPECT_GE(val1,val2); 	val1 >= val2

ASSERT_STREQ(str1,str2); 	EXPECT_STREQ(str1,str2); 	the two C strings have the same content
ASSERT_STRNE(str1,str2); 	EXPECT_STRNE(str1,str2); 	the two C strings have different content
ASSERT_STRCASEEQ(str1,str2); 	EXPECT_STRCASEEQ(str1,str2); 	the two C strings have the same content, ignoring case
ASSERT_STRCASENE(str1,str2); 	EXPECT_STRCASENE(str1,str2); 	the two C strings have different content, ignoring case

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×