Test Complete的性能记录方法

发表于:2007-8-27 14:11

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:陈能技    来源:陈能技的质量感悟

        Test Complete主要是一个功能测试工具,利用其对GUI控件的识别、动作记录、回放等脚本技术实现替代部分的人工测试的执行。但是它同时还提供很多机制让我们在功能测试的同时记录性能。
 
MemUsage,CPUUsage
        可利用TC(Test Complete)的sys对象的属性获得关于进程和操作系统的内存、CPU使用情况。
 
        下面脚本记录当前所有进程和操作系统使用的内存:
   log.Message(VarToStr(Sys.MemUsage)+'%'); 
 
        下面脚本记录notepad进程的当前内存使用情况:
   Log.Message(VarToStr(Sys.Process('notepad').MemUsage)+'K');
  
 
        通过访问Sys对象,可以获取关于CPU的各种信息,例如,CPU处理器、处理器个数、CPU使用率(包括系统的和某个具体进程的)
   //Information on the processor(s) installed on the current computer.
   log.Message( Sys.CPU);
   //Returns the number of processors installed on the current computer.
   log.Message( Sys.CPUCount);
   //Current percentage of CPU time used by the operating system and all running processes.
   log.Message( VarToStr(Sys.CPUUsage)+'%');   
   //the current approximate percentage of the CPU time spent running the process.
   log.Message( VarToStr(Sys.Process('notepad').CPUUsage)+'%'); 
  
        注意:使用TC提供的VarToStr函数把Sys对象的各种属性变量值转换成String类型,否则log信息无法显示值。
 
与AQTime集成
        上面说的方法是TC本身提供的,只能记录基本的性能参数,例如内存、CPU,TC还提供另外的途径记录性能,例如通过与AQTime集成的方式,AQTime是AutomatedQA公司出品的代码性能测试工具,它能在程序执行过程中记录每行代码的执行效率,内存使用情况、代码覆盖率等。
 
        与AQTime集成有两种方式。一种是调用AQTime软件的方式,另外一种是直接使用AQTime提供的接口对象。
 
        如果采用第一种方式,则首先应该把TC的TestedApps的执行模式改成 Profile 模式,可在TestedApps editor中设置,也可在脚本中设置,例如:
 
var
 MyApp : OleVariant;
begin
 // Obtains the tested application
 MyApp := TestedApps.MyTestedApp;
 
 // Specifies the run mode parameters
 MyApp.Params.ProfileParams.AQtimeVersion := 5;
 MyApp.Params.ProfileParams.ProfilerName := 'Coverage Profiler';
 MyApp.Params.ProfileParams.RunMode := 'Normal';
 MyApp.Params.ProfileParams.UseProject := False;
 
 // Activates the Profile run mode
 MyApp.Params.ProfileParams.Activate;
 ...
end;
 
        第二种方式是采用访问提供的编程对象的方式,提供AQtimeIntegration 、AQtime、slAQtime对象来访问AQTime的各种功能。
 
        例如,下面脚本使用AQtimeIntegration 和AQtime对象,首先通过AqtimeIntegration对象的IsSupportedVersionAvailable属性判断某版本的AQTime是否存在,如果存在,则指定CurrentVersion为某版本的AQTime,然后通过AQTime对象的CreateProjectFromModule方法创建一个新的AQTime项目,通过SelectProfiler方法指定Profile的类型,通过StartProfiling方法开始Profile,通过WaitAndExportResults输出结果。
 
procedure TestAQtime;
begin
 // Checks AQtime version
 if not AQtimeIntegration.IsSupportedVersionAvailable('4') then
 begin
    Log.Error('The required version of AQtime is not installed.');
    Exit;
 end;
 
 // Specifies the desired AQtime version
 AQtimeIntegration.CurrentVersion := 4;
 
 // Creates a new project
 if not AQtime.CreateProjectFromModule('C:\MyTestedApp\MyTestedApp.exe') then
 begin
    Log.Error('Cannot open the project.');
    Exit;
 end;
 
 // Selects the desired profiler
 if not AQtime.SelectProfiler('Performance Profiler') then
 begin
    Log.Error('Cannot select the specified profiler.');
    Exit;
 end;
 
 // Starts profiling
 if not AQtime.StartProfiling() then
 begin
    Log.Error('Cannot start profiling.');
    Exit;
 end;
 
 // Waits until the profiling is over and
 // exports profiling results
 AQtime.WaitAndExportResults('C:\MyTestedApp\MySummaryResults.xml',
                              'C:\MyTestedApp\MyResults.xml');
 
 // Closes AQtime
 AQtime.Close();
end;
21/212>
《2023软件测试行业现状调查报告》独家发布~

精彩评论

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号