google test把單元測試**分成三個概念, 第一test,每個斷言 assertion都稱為test。第二test case,包含一組test(assertion)或者乙個test,test case之間也不相互干擾。第三 test program,包含一組或者乙個test case。下面的例子會清晰的說明這三者之間的關係。
1 #include
2 #include
3 using namespace std;45
67 int just_return(int n)
8 12
13 return n;
14 }
1516 test( just_return, input_10_20)//稱為 test case
17 22
23 test( just_return, input_100)
24 28
2930 int main( int argc, char **ar**)
31 {
32 cout<<"hello gtest"《編譯時候只要包括include和lib 路徑既可以。lib下提供了靜態和動態兩種lib,編譯方法如下
靜態庫--g++ test.cpp ./lib/libgtest_main.a -i./include/
動態庫--g++ test.cpp -i ./include/ -lgtest_main -l./lib/
export ld_library_path=libgtest_main.so所在的目錄。
執行結果如下,failed的專案都會用紅色來標識,其餘的用綠色。清楚的說明了哪個函式失敗,在第幾行。
[**********] running 2 tests from 1 test case.
[----------] global test environment set-up.
[----------] 2 tests from just_return
[ run ] just_return.input_10_20
[ ok ] just_return.input_10_20
[ run ] just_return.input_100
test.cpp:25: failure
value of: just_return(100)
actual: -1
expected: 100
[ failed ] just_return.input_100
[----------] global test environment tear-down
[**********] 2 tests from 1 test case ran.
[ passed ] 1 test.
[ failed ] 1 test, listed below:
[ failed ] just_return.input_100
對於那些斷言如何使用,請參見google test的幫助文件。
小試Googletest記二
學習了gtest的一些基礎知識後進入了玩轉google開源c 單元測試框架google test系列 gtest 之四 引數化,引數化的測試在平時的應用中應該也比較常見,原博主介紹的例子非常簡潔,琢磨著怎樣根據自己的需要定製引數,而不是簡單的使用基本變數 int之類的 就拿原博主之前用的foo函式 ...
Google Test 使用筆記
編譯gtest 使用vs2015開啟gtest.sln 我的是在目錄googletest master googletest msvc 2010下 在debug release兩個模式下都編譯一下。編譯後,在msvc gtest 下有debug release兩個資料夾。編譯器報 不是有效的win3...
googleTest安裝和使用
環境 windows7 vs2013 一 安裝 2.解壓googletest,目錄googletest msvc 下是visual studio的工程檔案,使用vs開啟,分別用debug和release模式編譯 3.編譯完成後進入googletest msvc gtest 資料夾下,有debug和r...