Gtest框架简介
-
Gtest是Google Test的简称,是Google开发的C++单元测试框架;
适用于多个平台: Liunx, Mac OS X, Windows, Cygwin, Windows CE and Symbian, PlatformIO -
Gtest 是基于xUnit框架编写,和Junit, PyUnit 非常相似
-
官方网站: https://github.com/google/googletest
-
官方文档: https://github.com/google/googletest/blob/master/googletest/docs/primer.md
Gtest框架测试流程
断言
实例
全局的SetUp和TearDown
class FooEnvironment : public testing::Environment
{
public:
virtual void SetUp()
{
std::cout << "Foo FooEnvironment SetUP" << std::endl;
}
virtual void TearDown()
{
std::cout << "Foo FooEnvironment TearDown" << std::endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
testing::AddGlobalTestEnvironment(new FooEnvironment);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}