最近學習了白盒測試。白盒測試的測試方法有很多種:代碼檢查法、靜態結構分析法、靜態質量度量法、邏輯覆蓋法、基本路徑測試法、域測試、符號測試、路徑覆蓋和程序變異。白盒測試法的覆蓋標准有邏輯覆蓋、循環覆蓋和基本路徑測試。其中邏輯覆蓋包括語句覆蓋、判定覆蓋、條件覆蓋、判定/條件覆蓋、條件組合覆蓋和路徑覆蓋。六種覆蓋標准發現錯誤的能力呈由弱到強的變化:
void LeapYear(int year);
void main() {
int year=0;
LeapYear(year);
}
void LeapYear(int year) {
cout<<"請輸入年份:"<<endl;
cin>>year;
while(!(year>=1811 && year<=2013)) {
cout<<"年份超過界限,請重新輸入"<<endl;
cin>>year;
}
if((year%4==0 && year%100!=0) || (year%400==0)) { //檢查閏年
cout<<"閏年"<<endl;
}
else{
cout<<"不是閏年"<<endl;
}
}
測試用例:
改良后的代碼:
public void handle(MouseEvent arg0) {
boolean judge1 = true;
boolean judge2 = true;
String s = textfiled1.getText();
if ((s.length() > 6) || (s.length() < 1))
{
text.setText(str2);
return;
for (int i = 0; i < s.length();i++)
{
char c = s.charAt(i);
if (!((c >= 'A' && c <= 'Z')||(c >= 'a' && c <='z')||(c >= '0' && c <= '9')))
{
judge1 = false;
break;
}
}
if (!judge1)
{
text.setText(str2);
return;
}
s = textfiled2.getText();
if ((s.length() > 6) || (s.length() < 1))
{
text.setText(str2);
return;
}
for (int i = 0; i < s.length();i++)
{
char c = s.charAt(i);
if (!((c >= 'A' && c <= 'Z')||(c >= 'a' && c <='z')||(c >= '0' && c <= '9')))
{
judge2 = false;
break;
}
}
if (!judge2)
{
text.setText(str2);
return;
}
s = textfiled3.getText();
int i=Integer.parseInt(s);
if (i != a)
{
text.setText(str2);
}
else
{
text.setText(str1);
}
}
});*/
測試用例: