Download Google Test source
Compile GTest
- Open ./msvc/gtest.sln by Visual Studio 2012
- Properties -> C/C++ -> Preprocessor -> Preprocessor define: add _VARIADIC_MAX = 10
- Properties -> C/C++ -> Code Generation -> Runtime library: DLL(/MD) in release or DLL(/MDd) in debug
- Compile gtest and gtest_main projects
Output Library
- debug/gtestd.lib
- debug/gtest_maind.lib
- release/gtest.lib
- release/gtest_main.lib
Example
//testGTest.h
#ifndef TESTTOOLS_TESTGTEST_H_
#define TESTTOOLS_TESTGTEST_H_
#define _VARIADIC_MAX 10 //for vs2012
#include "gtest\gtest.h"
namespace TEST_GTEST {
int Add(const int a, const int b);
}
#endif //TESTTOOLS_TESTGTEST_H_
//testGtest.cpp
#include "stdafx.h"
#include "testGTest.h"
int TEST_GTEST::Add(const int a, const int b) {
return a + b;
}
TEST(AddTest, HandlesPositiveInput) {
EXPECT_LT(1, TEST_GTEST::Add(1, 2));
EXPECT_EQ(3, TEST_GTEST::Add(1, 2));
ASSERT_LT(1, TEST_GTEST::Add(1, 2));
ASSERT_EQ(3, TEST_GTEST::Add(1, 2));
}
//testTools.cpp
#include "stdafx.h"
#include "testGTest.h"
int _tmain(int argc, _TCHAR* argv[])
{
{ //test gtest
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
}
getchar();
return 0;
}
Reference