您的位置:
中国软件测试联盟  >> 资讯  >> 行业精华  >> 查看资讯

为什么测试全覆盖很难?

[ 来源: 网络转载 | 作者:佚名 | 时间:2007-9-03 13:36 ]

正面观点:100%的覆盖是可以的,为什么呢?看下面的代码:


我们有这样的一个方法:

public int getAccount(){
return 999;
}

这样的方法走一次就可以了,你只要执行它(System.out.pringln(xxx.getAccount()))它就会乖乖的返回999,测试一次自然100%覆盖,看我说的对吧!

有一天这个方法忽然变化了:

public int getAccount(int selet){
switch{
  case 1:
    return 1;
    breake;
  case 2:
    return 2;
    breake;
  case 3:
    return 3;
    breake;
  default:
    return 0;
    breake;
}
}

汗,豁出去了我执行四次,哈哈,我也达到了100%的覆盖,我说的还是正确的!

继续,某天雷电辟中了代码,代码立刻膨胀了,现在变成:

public int getAccount(int selet){
switch{
  case 1:
    if (xxx) then{
      return 0;
    }else{
      return 1;
    }
    breake;
  case 2:
    if (xxx) then{
      return 0;
    }else{
      return 2;
    }
    breake;
  case 3:
    if (xxx) then{
      return 0;
    }else{
      return 3;
    }
    breake;
  ......

  case 9999999:(假如java允许,哈哈)
    if (xxx) then{
      return 0;
    }else{
      return 999999;
    }
    breake;
  default:
    return 0;
    breake;
}
}

可能要做到100%地球都爆炸了,这就是为什么愿望是好的,实现是困难的根源!


Tags:
打印

>> 相关资讯:

上一篇   下一篇
 
-5 -3 -1 - 1 3 5

评分

您的评论

我来说两句

seccode

·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为