Installation
เอามาจาก README ของมัน
เวลา compile
$ g++ -I${GTEST_DIR}/include -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest-all.cc
$ ar -rv libgtest.a gtest-all.o
เวลา compile
-I ${HOME}/gtest-1.5.0/include -L ${HOME}/gtest-1.5.0/ -lgtest
Demo
เอามาจากเวปของ ibm
EXPECT v.s. ASSERT = non-fetal v.s. fetal
#include "gtest/gtest.h"
TEST(SquareRootTest, PositiveNos) {
EXPECT_EQ (18.0, square-root (324.0));
EXPECT_EQ (25.4, square-root (645.16));
EXPECT_EQ (50.3321, square-root (2533.310224));
}
TEST (SquareRootTest, ZeroAndNegativeNos) {
ASSERT_EQ (0.0, square-root (0.0));
ASSERT_EQ (-1, square-root (-22.0));
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
EXPECT v.s. ASSERT = non-fetal v.s. fetal
EXPECT : execution continues even if there is a failure
ASSERT : test execution abort
ความคิดเห็น