Google Test (Googleã®C++åãã¦ããããã¹ããã¬ã¼ã ã¯ã¼ã¯) 使ã£ã¦ã¿ãã¡ã¢
ç°¡åã«ä½¿ãæ¹ãã¡ã¢
SVNãªã©ã§ã½ã¼ã¹ã³ã¼ããåã£ã¦ããã
svn checkout http://googletest.googlecode.com/svn/trunk/ googletest
ã©ã¤ãã©ãªãã¡ã¤ã«ãä½ã
READMEã«ãã㨠CMake ãããããããããCMake ããã¦ãªãã£ãã®ã§ãbrew install cmake
ã§ã¤ã³ã¹ãã¼ã«ãã¦ããããããã¦ã以ä¸ã®æé ã§ã©ã¤ãã©ãªãã¡ã¤ã«ãä½æã
cd googletest mkdir build cmake ..
ããã§ãã«ã¬ã³ããã£ã¬ã¯ããªã®ä¸ã« Makefile ãã§ãã¦ããã®ã§ã
make
ããã¨ãlibgtest.a 㨠libtest_main.a ãåºæ¥ãããããã®ã©ã¤ãã©ãªããã¹ãã³ã¼ãã¨ä¸ç·ã«ãªã³ã¯ãããã¨ã§ãã¹ãã³ã¼ããå®è¡ãããã¡ã¤ã«ãçæããããlibgtest.a ã¯ãã¬ã¼ã ã¯ã¼ã¯ã®æ¬ä½ã§ãlibgtest_main.a ã¯ãã¬ã¼ã ã¯ã¼ã¯ãç¨æãã¦ããmain()
é¢æ°ãèªåã§main()
é¢æ°ãæ¸ãå ´åã¯ãå¾è
ããªã³ã¯ããå¿
è¦ã¯ãªãã
ãã¹ãã³ã¼ãã®ã³ã³ãã¤ã«ãå®è¡
æ©éãã¹ãã³ã¼ããæ¸ãã¦ã¿ãã以ä¸ã®ãã¼ã¸ããã¡ããã£ã¨æåããã
ãã®ï¼ï¼åºæ¬çãªä½¿ãæ¹ - ã¨ã³ã¸ãã¢ã®ã½ããã¦ã§ã¢çææ
åããããããããããããã¨å¤±æãããã¹ãã«æ¸ãæããã
ä¸è¨ã®ã³ã¼ãã test.cc ã¨ãã¦ä¿åãã¦ã以ä¸ã®ããã«ã³ã³ãã¤ã«ããããã®ã³ã¼ãã«ã¯main()
é¢æ°ãç¡ãã®ã§ãlibgtest_main.a ã¨ãªã³ã¯ãã¦ããããã¨ã§ããã¬ã¼ã ã¯ã¼ã¯ãç¨æãã¦ããmain()
é¢æ°ã¨ãªã³ã¯ãããã
g++ -I${GTEST_DIR}/include test.cc ${GTEST_DIR}/build/libgtest_main.a -o test
ä¸è¨ã®éãã³ã³ãã¤ã«ããã¨ãã«ã¬ã³ããã£ã¬ã¯ããªé ä¸ã« test ãã¡ã¤ã«ãåºæ¥ã¦ããã¯ããªã®ã§ããã®ã¾ã¾å®è¡ãã¦ã¿ãã以ä¸ã®ãããªçµæã«ãªã£ãããã²ã¨ã¾ããã¹ããåãã¦ãããã¨ã確èªã§ãã証æ ã
ãããã«ãã½ã¼ã¹ã³ã¼ããä¿®æ£ãã¦ã¿ãã
int add(int x, int y) { return x + y; }
ã§ãããä¸åº¦ã³ã³ãã¤ã«ï¼å®è¡ã
ä»åº¦ã¯ãã¹ãéã£ãã
ãããªæãã§ãã¹ãã§ããã£ã½ãã使ã£ã¦ã¿ããã