学习使用Google Test
配置好VS后, 编写第一个Demo.
1: // gTest.cpp : 定义控制台应用程序的入口点。
2: //
3:
4: #include "stdafx.h"
5:
6: int Foo(int a, int b)
7: {
8: if (a == 0 || b == 0)
9: {
10: throw "don't do that";
11: }
12: int c = a % b;
13: if (c == 0)
14: return b;
15: return Foo(b, c);
16: }
17:
18: int Add(int a, int b)
19: {
20: return a + b;
21: }
22:
23: #include <gtest/gtest.h>
24:
25: TEST(FooTest, HandleNoneZeroInput)
26: {
27: EXPECT_EQ(2, Foo(4, 10));
28: EXPECT_EQ(6, Foo(30, 18));
29: //ASSERT_EQ(3, Foo(3, 6));
30: //ASSERT_EQ(3, Foo(3, 7));
31: //EXPECT_EQ(3, Foo(5, 7));
32: }
33:
34: TEST(AddTest, HandleNoneZeroInput)
35: {
36: EXPECT_EQ(2, Add(1, 1));
37: //EXPECT_EQ(2, Add(1, 2));
38: }
39:
40: int _tmain(int argc, _TCHAR* argv[])
41: {
42: testing::InitGoogleTest(&argc, argv);
43: return RUN_ALL_TESTS();
44: }
45:
运行结果如下图所示:
摘自 eryar
补充:软件开发 , C++ ,