(1) 下載gtest-1.4.0.tar.bz2
tar jxvf gtest-1.4.0.tar.bz2
(2) ./configure
make
sudo make install
ldconfig // 因為它有灌library
(3) 準備要被測的檔案
for example: humorless.h
///////// 內容 ///////////
class Sample
{
public:
int return_100()
{
return 100;
}
};
/////////////////////////
(4) 準備好test suite
for example: tester.cpp
///////////// 內容 ///////////
#include
#include "humorless.h"
TEST(Sample, return_100) {
Sample c;
// EXPECT_EQ() evaluates its arguments exactly once, so they
// can have side effects.
EXPECT_EQ(0, c.return_100());
EXPECT_EQ(1, c.return_100());
EXPECT_EQ(2, c.return_100());
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
//////////////////////////
(5) g++ -o tester tester.cpp -lgtest
./tester
// 記得要去link 啊…