잠토의 잠망경

GTest Setup 본문

공부/Cpp

GTest Setup

잠수함토끼 2013. 6. 30. 20:40

GTest는 Unit Test를 위하여 Google에서 제공한 Test Module이라 보면 된다.

설치 방법은 아래와 같다.

 

순서

설명

1

 

 

http://code.google.com/p/googletest/ 은 GoogleTest Site이다.

여기서 Downloads를 들어가세요.

2

 

 

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

여기서 최신 Version을 받으시기 바랍니다. 현재 시점 gtest-1.6.0.zip 을 download 하세요.

3

 

 

Download가 완료되면 적당한 위치에 놓고 압축을 푸세요. 저는 C:\에 놓고 압축을 해제합니다.

4

 

그러면 다음과 같이 C:\gtest-1.6.0\ 이라는 폴더가 생성되고 다음과 같이 File들과 Directory를 확인할 수 있습니다.

5

 

 

압축을 풀고 나면 해당 Directory는 다음과 같이 읽기 전용으로 되어 있습니다. 읽기 전용해제해주세요.

 

 

적용을 누르면 해당 폴더 밑으로는 읽기 전용이 해제됩니다.

6

 

 

C:\gtest-1.6.0\msvc\gtest.sln을 더블 클릭합니다. 현재 설명자는 Visual Studio2005 사용중입니다.

7

 

 

다음과 같이 Visual Studio 변환 마법사가 시작됩니다. 다음 클릭

8

 

 

아니오를 선택하고 다음 클릭

9

 

 

마침을 눌러주세요.

10

 

 

닫기를 눌러주세요.

 

11

 

 

그럼 다음 Reporting과 함께 변환이 마무리 됩니다.

12

 

 

이제 마무리되었으니 컴파일 작업에 들어갑니다. 그럼 완료 되었군요.

13

 

 

C:\gtest-1.6.0\msvc\gtest\Debug\에 gtest_maind.lib, gtestd.lib 가 정상적으로 생성되었는지 확인하세요.

14

 

 

Visual Studio 2005 기준 도구-옵션-프로젝트 및 솔루션 VC++ 디렉토리로 이동하세요.

포함 파일을 누르고 C:\gtest-1.6.0\include 를 추가하세요.

 

 

라이브러리 파일을 누르고 C:\gtest-1.6.0\msvc\gtest\Debug 를 추가하세요.

15

 

 

 

제대로 작동하는지 Sample을 돌려보죠. 위와 같이 콘솔 응용 프로그램을 하나 만듭니다.

16

 

  1. #include "stdafx.h"  
  2. #include <gtest/gtest.h>  
  3.   
  4.   
  5.   
  6. #pragma comment(lib,"gtest_maind.lib")  
  7. #pragma comment(lib,"gtestd.lib")  
  8.   
  9.   
  10. int Add(int a, int b)  
  11. {  
  12.   
  13.     return a+b;  
  14. }  
  15.   
  16. TEST(addTest, Add11)  
  17. {  
  18.     EXPECT_EQ(2, Add(1,1));  
  19. }  
  20.   
  21.   
  22.   
  23.   
  24.   
  25. int _tmain(int argc, _TCHAR* argv[])  
  26. {  
  27.     testing::InitGoogleTest(&argc,argv);  
  28.   
  29.   
  30.     return RUN_ALL_TESTS();  
  31. }  

 

Sample Code를 다음과 같이 입력해주세요. 그리고 Compile

17

 

 

그럼 위와 같이 Link Error 가 발생합니다.

 

gtestd.lib(gtest-all.obj) : error LNK2005: "public: void __thiscall std::basic_stringstream

 

대충 이런 오류인데 해결 방법은 다음과 같습니다.

(참고: https://groups.google.com/forum/#!msg/googletestframework/5ulkq01Jl-Q/ASngWOn4BtcJ)

18

 

 

다음과 설정하고 재컴파일하면 정상적으로 Compile 됩니다.

19

 

 

정상적으로 동작함을 확인 할 수 있습니다.

 

 

※ 참고하였던 Site

http://stdcall.tistory.com/5

http://studior.egloos.com/m/1910102

https://docs.google.com/presentation/d/1ArHbOMZNSR-3i04BbuYFkvEh7rzfRgi53vpFl8wDeqo/present#slide=id.i0

http://jakejang.tistory.com/33

http://www.slideshare.net/zone0000/c-7522148

http://blog.naver.com/PostView.nhn?blogId=arcangeleri&logNo=90089351278

http://surpreem.com/archives/626#sthash.4HpAlya0.dpbs

http://moltak.tistory.com/295

https://groups.google.com/forum/#!msg/googletestframework/5ulkq01Jl-Q/ASngWOn4BtcJ

Comments