1. 요구사항
Microsoft Visual C++ 7.1 or newer
CMake 2.6.4 or higher
2. GTest 다운로드
http://code.google.com/p/googletest/
3. Target Build
CMake 를 이용하여 library와 dll 을 생성한다.
- source code : GTest 설치 경로 선택 (CMakeLists.txt 위치 경로)
- binaries : 라이브러리 생성 폴더
Configure 후 BUILD_SHARED_LIBS를 선택한 후 Generate를 클릭하면 솔루션 파일 생성
gtest.sln 파일을 클릭하여 컴파일 하면 lib 파일을 얻을 수 있다. C/C++ –> Code Generation –> Runtime Library에서 /MT MTd /MD /MDd 모드 중 gtest를 사용하려는 프로젝트의 환경과 동일한 설정을 사용해야 한다.
4. 프로젝트 적용
필요 파일 : header(gtest폴더 내 존재), lib(Target build 과정에서 생성) 파일
C/C++ –> General –> Additional Include Directories 에서 헤더파일 경로 추가
Linker –> General –> Additional Library Directories 에서 라이브러리 경로 추가 혹은 #pragma comment(lib, “경로/gtest.lib”)를 사용해도 된다.
Linker –> Input –> Additional Dependencies 에 라이브러리 이름 기입
실행 파일 생성 위치에 dll 파일 복사(필요한 경우)
아래의 경우는 working directory를 설정하고 해당 위치에 복사
5. 예제 코드 작성
#include "gtest/gtest.h"
int sub(int a, int b)
{
return a-b;
}
TEST(FirtTest)
{
EXPECT_EQ(5, sub(4,2));
EXPECT_EQ(2, sub(4,2));
}
int main(int argc, char* argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
6. 결과
※ 실습 환경
Windows 7 Ultimate K
Visual Studio 2008