-
Notifications
You must be signed in to change notification settings - Fork 0
[Tool] gtest little tutorial
Hu, Hsien-Wen edited this page Dec 26, 2017
·
1 revision
如題,這個wiki 頁面帶給大家一個非常簡易gtest教學,分享 tomyhu1995 所知道的東西
- 你需要安裝gtest在你的電腦: 目前所使用的方法都是將gtest直接安裝在電腦上
- Include files: 記得 `#include<gtest/gtest.h>
- Compile: 必須要加上
-lgtest_main',-lgtest,-lpthread`. - Main program: Main program 必須採用C++撰寫,其餘的library可以使用C/C++。
這邊會提供一個簡單的範例讓大家迅速的了解gtest怎麼使用:
#include <gtest/gtest.h>
TEST(multiply, error)//會顯示在gtest的結果上,請使用者輸入正確的測試單元名稱
{
int a = 5;
int b = 1;
ASSERT_EQ(5, a*b);//檢查是否正確
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}這個測試程式會run所有的TEST,其中我們所設計的test case是檢查a * b是不是等於5。
在前一部份我們僅僅使用了 ASSERT_EQ進行測試,然而gtest提供了非常多方便的functions,希望有更多能人補齊這份文件。