有谁用过gtest的吗?
#include "stdafx.h"
#include <gtest.h>
//用TEST做简单测试
TEST(TestFactorial, ZeroInput) //第一个参数是测试用例名,第二个参数是测试名:随后的测试结果将以"测试用例名.测试名"的形式给出
{
EXPECT_EQ(1, Factorial(0)); //EXPECT_EQ稍候再说,现在只要知道它是测试两个数据是否相等的就行了。
}
TEST(TestFactorial, OtherInput)
{
EXPECT_EQ(1, Factorial(1));
EXPECT_EQ(2, Factorial(2));
EXPECT_EQ(6, Factorial(3));
EXPECT_EQ(40320, Factorial(8));
}
int main(int argc, char* argv[])
{
testing::InitGoogleTest(&argc,argv); //用来处理Test相关的命令行开关,如果不关注也可不加
RUN_ALL_TESTS(); //看函数名就知道干啥了
std::cin.get(); //只是让它暂停而已,不然一闪就没了
return 0;
}