testhelp.h是作者為redis量身定做的單元測試框架,對于redis這種規(guī)模的項目,就沒有必要上GTEST這種大殺器了,作者18行代碼搞定。
不過很遺憾,在2.4.10這個版本的版本的redis中,只有sds用了這個測試框架,不知其他代碼作者是如何做測試的。我慢慢摸索,摸索到了告訴大家。
1
#ifndef __TESTHELP_H
2
#define
__TESTHELP_H
3
4
int
__failed_tests =
0
; //失敗的測試用例數(shù)
5
int
__test_num =
0
; //總的測試用例數(shù)
6
#define
test_cond(descr,_c) do { \
7
__test_num++; printf(
"
%d - %s:
"
, __test_num, descr); \
8
if
(_c) printf(
"
PASSED\n
"
);
else
{printf(
"
FAILED\n
"
); __failed_tests++
;} \
9
}
while
(
0
);
10
#define
test_report() do { \
11
printf(
"
%d tests, %d passed, %d failed\n
"
, __test_num, \
12
__test_num-
__failed_tests, __failed_tests); \
13
if
(__failed_tests) { \
14
printf(
"
=== WARNING === We have failed tests here...\n
"
); \
15
} \
16
}
while
(
0
);
17
18
#endif //完全用宏實現(xiàn)的,一目了然,不多說了
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

