软件测试基础 - 集成测试(实战部分)

 

//对以下模块进行集成测试,分别用大爆炸模式和自顶向下模式进行测试。

int moduleA(int x, int y)
{
 int resA=0;
 if(x>100) resA=-1;
 else if(x>0) resA=moduleB(x, y);
 else if(x==0) resA=moduleC(y);
 else if(x>-100) resA=moduleD(x, y);
 else resA=-1;
 return resA;
}
int moduleB(int x, int y)
{
 int resB=0;
 if(x==5) resB=-1;
 else resB=moduleE(y);
 return resB;
}

int moduleC(int x)
{
 return x*x+2;
}

int moduleD(int x, int y)
{
 int resD=0;
 if(x==-1) resD=-1;
 else resD=moduleF(y);
 return resD;
}

int moduleE(int x)
{
 return x+1;
}

int moduleF(int x)
{
 return 1-x;
}

首先,画出模块之间的关系图

1.大爆炸的测试

Step1:
      接收测试用例的输入、预期结果; 
Step2:
      调用被测对象;
Step3:
      比较预期结果和实际结果  相同: PASS 不同:Fail;

bigbang_driver(int x,int y,int expRes){
  int actRes=moduleA(x,y);
  if(actRes==expRes)
  printf("Testcase Pass!\n");
  else
  printf("Testcase Fail!\n");
 }            
 main(){
   bigbang_driver(1,9,10);    //A-B,B-E
   bigbang_driver(0,3,11);    //A-C
   bigbang_driver(-99,9,-8);    //A-D,D-F
  
   system("Pause");
}       
    

2.自顶向下测试

Step1:
       测试AB,设计AB的驱动,针对CDE分别打桩;
Step2:
       测试ABE,利用AB的驱动,针对CD打桩;
Step3:
       测试ABEC,利用AB的驱动,针对D打桩;

topdown_driver(int x,int y,int expRes){
  int actRes=moduleA(x,y);
  if(actRes==expRes)
  printf("Testcase Pass!\n");
  else
  printf("Testcase Fail!\n");
}             

int moduleC_stub(int x)
{
 //return x*x+2;
 if(x==5) return 27;  
}


int moduleD_stub(int x, int y)
{
    /* 
 int resD=0;
 if(x==-1) resD=-1;
 else resD=moduleF(y);
 return resD;
 */ 
 if(x==-99&&y==8) return -7; 
}
/* step1
int moduleE_stub(int x)
{
 //return x+1;
 if(x==9) return 10; 
}
*/

//step2
int moduleE(int x)
{
 return x+1;
}

main(){
   topdown_driver(1,9,10);    //AB-E
   topdown_driver(0,5,27);    //AB-C
   topdown_driver(-99,8,-7);  //AB-D
   system("Pause");            
}

 

posted @ 2016-05-04 10:35  Caroline-Li  阅读(1110)  评论(0编辑  收藏  举报