シンプルで扱いやすいと耳にして、早速ダウンロード。
GitHub - google/googletest: Google Test
サンプルコードを眺めているところですが、確かに簡単そう。試してみます。
最初のテスト
#include <gtest/gtest.h> // テストされる関数 int add(int x, int y) { return x + y; } // テストする関数: テストケース名 AddTest / テスト名 Add TEST(AddTest, Add) { EXPECT_EQ(1, add(1, 0)); EXPECT_EQ(1, add(0, 1)); EXPECT_EQ(2, add(1, 1)); } // テストの実施 int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
$ g++ -ansi -Wall gtest_test.cpp -lgtest
実行結果。
[==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from AddTest [ RUN ] AddTest.Add [ OK ] AddTest.Add [----------] Global test environment tear-down [==========] 1 test from 1 test case ran. [ PASSED ] 1 test.
扱いやすくてなんかいい感じです。