forked from idehong/ltest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo3.lua
134 lines (99 loc) · 2.54 KB
/
demo3.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--[[
//////////////////////////////////////////////////////////////////////////
// date : 2013-5-4
// auth : macroli([email protected])
// ver : 0.2
// desc : demo
//////////////////////////////////////////////////////////////////////////
--]]
------------------------------------------------------------------------------
require("ltest")
local function MyAdd(a, b)
return a + b
end
local function TestAdd1()
ltest.ASSERT_EQ(2, MyAdd(1, 1))
end
local function MySub(a, b)
return a - b
end
-- for test case
CMyTestEnv = ltest.TestEnvironment:new()
function CMyTestEnv:new(oo)
local o = oo or {}
setmetatable(o, self)
self.__index = self
return o
end
function CMyTestEnv.SetUp(self)
print("CMyTestEnv.SetUp")
end
function CMyTestEnv.TearDown(self)
print("CMyTestEnv.TearDown")
end
-- for test case
CMyTestCase2 = ltest.TestCase:new()
function CMyTestCase2:new(oo)
local o = oo or {}
setmetatable(o, self)
self.__index = self
return o
end
function CMyTestCase2.TestCase21(self)
ltest.ASSERT_EQ(0, MySub(1, 1))
end
function CMyTestCase2.TestCase22(self)
ltest.ASSERT_EQ(0, MySub(1, 2))
end
-- for test case
CMyTestCase3 = ltest.TestCase:new()
function CMyTestCase3:new(oo)
local o = oo or {}
o.count = 1
setmetatable(o, self)
self.__index = self
return o
end
function CMyTestCase3.SetUpTestCase(self)
self.count = 1 + self.count
print("CMyTestCase3.SetUpTestCase")
end
function CMyTestCase3.TearDownTestCase(self)
self.count = 1 + self.count
print("CMyTestCase3.TearDownTestCase")
end
function CMyTestCase3.SetUp(self)
self.count = 1 + self.count
print("CMyTestCase3.SetUp")
end
function CMyTestCase3.TearDown(self)
self.count = 1 + self.count
print("CMyTestCase3.TearDown")
end
function CMyTestCase3.Case31(self)
self.count = 1 + self.count
ltest.ASSERT_EQ(0, MySub(1, 1))
end
function CMyTestCase3.Case32(self)
self.count = 1 + self.count
ltest.ASSERT_EQ(1, MySub(10, 20))
end
function CMyTestCase3.Case33(self)
self.count = 1 + self.count
ltest.ASSERT_EQ(0, MySub(2, 2))
end
function main()
local tInitPara = {
ltest_filter = "CMyTestCase2.*:CMyTestCase3.*",
ltest_list_tests = "ltest_case_list.txt",
ltest_list_falied = "ltest_case_failed.txt",
}
ltest.InitLTest(tInitPara)
ltest.AddLTestCase(TestAdd1, "TestAdd1")
ltest.AddLTestSuite(CMyTestCase2:new(), "CMyTestCase2")
ltest.AddLTestSuite(CMyTestCase3:new(), "CMyTestCase3", "Case")
ltest.RunAllTests(CMyTestEnv:new())
local t = ltest.GetRunStatInfo()
--print(t.iFailedNum)
end
main()