應(yīng)用程序的接口不外乎三種,CLI——命令行接口,API——應(yīng)用編程接口和GUI。
因?yàn)楝F(xiàn)在有大把集成快速開發(fā)功能的IDE可供選擇,因此GUI的實(shí)現(xiàn)變得非常的順手。工具水平提高了,這看起來是理所當(dāng)然的事情。其實(shí)呢?
單一的GUI接口,帶來實(shí)現(xiàn)上的便利,用戶只和GUI打交道,他們也沒話說,那測試人員呢?有沒有換位思考過,各位DEV們?
GUI有一個特點(diǎn)就是不穩(wěn)定,元素的增減,是否顯示,顯示的位置,控件更新,都會引起GUI的變化,隨之引發(fā)了自動化腳本失效,這是個很讓人撓頭的問題,冒煙測試停住了,回歸也要大量人工介入。
需要提供更豐富的接口,CLI是一種不錯的選擇,因?yàn)镃LI不但可以用在單元測試,更可以用到系統(tǒng)測試階段,前提是整個軟件要提供相當(dāng)?shù)腃LI接口,讓交互可以自動化起來。
看一個Xerces參數(shù)處理的例子
中間有一個usage(),輸出使用幫助到屏幕
1
int argInd;
2
for (argInd = 1; argInd < argC; argInd++)
3
{
4
// Break out on first parm not starting with a dash
5
if (argV[argInd][0] != '-')
6
break;
7
8
// Watch for special case help request
9
if (!strcmp(argV[argInd], "-?"))
10
{
11
usage();
12
return 2;
13
}
14
else if (!strncmp(argV[argInd], "-v=", 3)
15
|| !strncmp(argV[argInd], "-V=", 3))
16
{
17
const char* const parm = &argV[argInd][3];
18
19
if (!strcmp(parm, "never"))
20
valScheme = AbstractDOMParser::Val_Never;
21
else if (!strcmp(parm, "auto"))
22
valScheme = AbstractDOMParser::Val_Auto;
23
else if (!strcmp(parm, "always"))
24
valScheme = AbstractDOMParser::Val_Always;
25
else
26
{
27
XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
28
return 2;
29
}
30
}
31
else if (!strcmp(argV[argInd], "-n")
32
|| !strcmp(argV[argInd], "-N"))
33
{
34
doNamespaces = true;
35
}
36
else if (!strcmp(argV[argInd], "-s")
37
|| !strcmp(argV[argInd], "-S"))
38
{
39
doSchema = true;
40
}
41
else if (!strcmp(argV[argInd], "-f")
42
|| !strcmp(argV[argInd], "-F"))
43
{
44
schemaFullChecking = true;
45
}
46
else if (!strcmp(argV[argInd], "-l")
47
|| !strcmp(argV[argInd], "-L"))
48
{
49
doList = true;
50
}
51
else if (!strcmp(argV[argInd], "-special:nel"))
52
{
53
// turning this on will lead to non-standard compliance behaviour
54
// it will recognize the unicode character 0x85 as new line character
55
// instead of regular character as specified in XML 1.0
56
// do not turn this on unless really necessary
57
58
recognizeNEL = true;
59
}
60
else if (!strcmp(argV[argInd], "-p")
61
|| !strcmp(argV[argInd], "-P"))
62
{
63
printOutEncounteredEles = true;
64
}
65
else if (!strncmp(argV[argInd], "-locale=", 8))
66
{
67
// Get out the end of line
68
strcpy(localeStr, &(argV[argInd][8]));
69
}
70
else
71
{
72
XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
73
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
74
}
75
}
76
77
//
78
// There should be only one and only one parameter left, and that
79
// should be the file name.
80
//
81
if (argInd != argC - 1)
82
{
83
usage();
84
return 1;
85
}
posted on 2009-05-20 10:12
創(chuàng)建更好的解決方案 閱讀(1423)
評論(0) 編輯 收藏 引用 所屬分類:
TDD 、
C++專欄 、
軟件測試 、
軟件設(shè)計(jì)