vs2012 中使用 gtest

1、下载:

http://code.google.com/p/googletest/downloads/list

2、编译:

用2012打开 gtest-1.6.0\msvc\gtest.sln, 编译gtest

此时会出错,有个解决的帖子:

http://code.google.com/p/googletest/issues/detail?id=412

其实就是一句话,

在  include\gtest\gtest.h 中添加#define _VARIADIC_MAX 10

#define GTEST_INCLUDE_GTEST_GTEST_H_

//add for vs2012
#define _VARIADIC_MAX 10

#include <limits>
#include <vector>

ok后会生成 gtestd.lib (release版为gtest.lib)

3、使用:

在测试项目属性中添加include和lib

一段demo:

#include "stdafx.h"
#include "gtest\gtest.h"

int fun(int a, int b)
{
	return (a-b);
}

TEST(fun, case1)
{
	EXPECT_LT(0, fun(1, 2));
}

int _tmain(int argc, _TCHAR* argv[])
{
	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}

4、推荐文章:

http://www.cnblogs.com/coderzh/archive/2009/03/31/1426758.html

只为更简单! --Rydiy

猜你喜欢

转载自blog.csdn.net/rydiy/article/details/8282960