如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
慧谷—博为峰软件测试工作室021-64471599www.51testing.com单元测试环境搭建指南博为峰软件技术有限公司www.51testing.com2008年1月修订记录日期修订版本修改章节修改描述作者2008-1-181.0初稿完成王琰第一步:利用VisualC++建立一个Win32ConsoleApplication工程,工程的名字为ManualTest因为被测对象有MFC类,所以该工程应该支持MFC:第二步:加入被测对象第三步:1)把下面的代码拷贝到文件ManualTest.cpp中:#include"counter.h"2)修改驱动函数,ManualTest.cpp文件中的_tmain方法修改ManualTest.cpp文件,在文件中加入如下蓝色字体部分:int_tmain(intargc,TCHAR*argv[],TCHAR*envp[]){intnRetCode=0;charfileline[255];//定义输入当前行字符串intbiscomment;//定义输入注释体内标志位intEx_biscomment;//定义预期输出注释体内标志位intEx_ret;//定义预期返回值代码行标志位intret;//定义实际返回值代码行标志位//initializeMFCandprintanderroronfailureif(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0)){//TODO:changeerrorcodetosuityourneedscerr<<_T("FatalError:MFCinitializationfailed")<<endl;nRetCode=1;}else{//TODO:codeyourapplication'sbehaviorhere.//CStringstrHello;//strHello.LoadString(IDS_HELLO);//cout<<(LPCTSTR)strHello<<endl;while(1){//接收用例参数printf("请输入用例参数:\n");printf("当前行字符串为:");gets(fileline);printf("注释体内标志位为:");scanf("%d",&biscomment);printf("预期输出注释体内标志位为:");scanf("%d",&Ex_biscomment);printf("预期输出代码行标志位为:");scanf("%d",&Ex_ret);fflush(stdin);//清除缓冲//调用被测函数CCountermcounter;ret=mcounter.IsCodeLine(fileline,biscomment);//比较实际结果和预期结果if(ret==Ex_ret&&biscomment==Ex_biscomment)printf("casepass!\n");elseprintf("casefail!\n");}}returnnRetCode;}第四步:设置头文件路径:在VC的tools/options/directories/includefiles中设置头文件路径:第五步:编译执行。