TEST(test case name,test name){EXPECT_EQ(28,val);//28和val相等返回tureEXPECT_NE(0,val);//0和val不等返回trueEXPECT_GT(29,val);//29大于val返回trueEXPECT_TRUE(val==28)<<"val somehow is not equal to 28";//不相等返回后面字符串//上述断言执行失败仍然会继续向下//下列断言如果执行失败会跳过下面代码ASSRET_EQ(28,val);//28和val相等返回tureASSRET_NE(0,val);//0和val不等返回trueASSRET_GT(29,val);//29大于val返回true//字符串比较EXPECT_STREQ("9","字符串");//浮点数比较EXPECT_FLOAT_EQ(7.0,((float)val)/4);EXPECT_DOUBLE_EQ(7.0,((double)val/4);}
2.测试装置类
classMyTest:public::testing::Test{protected:virtualvoidSetUp(){st.push(28);}//测试开始时运行virtualvoidTearDown(){}//测试结束时运行
Mystack st;MyTest({
std::cout <<"MyStackTest is constructed."<< std:: endl;st.push(22):}~MyTest(){
std:: cout <<"Destructing MyStackTest."<< std:: endl;}}TEST_F(MyTest,testPop){//在这里自动调用MyTest的实例,并且调用SetUp函数int val = st.pop();EXPECT_EQ(28,val);//在这里调用TearDown函数}TEST_F(MyTest,testPop2){//在这里自动调用MyTest的实例,并且调用SetUp函数int val = st.pop();EXPECT_EQ(28,val);//在这里调用TearDown函数}//两个TEST_F相互独立,两个不同的实例