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;
文章來源于領測軟件測試網 http://www.kjueaiud.com/