Class: ReportingStatistics
- Defined in:
- lib/tdriver/report/report_execution_statistics.rb
Instance Method Summary collapse
- #add_result_link(test_case, status, total, test_index) ⇒ Object
- #add_result_style_tag(status, total) ⇒ Object
- #collect_test_case_statistics ⇒ Object
- #generate_duration_graph(file_name) ⇒ Object
- #generate_statistics_headers ⇒ Object
- #generate_statistics_table ⇒ Object
-
#initialize(test_cases_array, summary = nil) ⇒ ReportingStatistics
constructor
A new instance of ReportingStatistics.
- #reset_total_statistics ⇒ Object
- #update_test_case_execution_statistics(tc_name, tc_status, tc_execution, duration, tc_link, reboots, crashes, connection_errors, dump_count, sent_bytes, received_bytes, memory_usage) ⇒ Object
- #update_total_execution_statistics(tc_status, reboots, crashes, connection_errors, dump_count, sent_bytes, received_bytes, memory_usage) ⇒ Object
Constructor Details
#initialize(test_cases_array, summary = nil) ⇒ ReportingStatistics
Returns a new instance of ReportingStatistics.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 22 def initialize(test_cases_array, summary=nil) @all_statuses=Array.new @group_test_case_arr=Array.new(test_cases_array) @pass_statuses= $parameters[ :report_passed_statuses, "passed" ].split('|') @fail_statuses= $parameters[ :report_failed_statuses, "failed" ].split('|') @not_run_statuses= $parameters[ :report_not_run_statuses, "not run" ].split('|') @test_results_per_page= $parameters[ :report_results_per_page, 50] @statistics_arr=Array.new @total_statistics_arr=Array.new @summary=summary end |
Instance Method Details
#add_result_link(test_case, status, total, test_index) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 275 def add_result_link(test_case,status,total,test_index) result_page=test_index/@test_results_per_page.to_i result_page_mod=test_index % @test_results_per_page.to_i if result_page_mod>0 result_page=result_page.to_i+1 end result_page=1 if result_page==0 if @summary tc_link='<a href="cases/'+result_page.to_i.to_s+'_chronological_total_run_index.html">' tc_link='<a href="cases/1_reboot_index.html">' if status=="reboots" && total>0 tc_link='<a href="cases/1_crash_index.html">' if status=="crashes" && total>0 tc_link='<a href="cases/1_connection_errors_index.html">' if status=="connection_errors" && total>0 tc_link='<a href="cases/1_'+@pass_statuses.first.gsub(' ','_')+'_'+test_case.gsub(' ','_')+'_index.html">' if @pass_statuses.include?(status) && total>0 tc_link='<a href="cases/1_'+@fail_statuses.first.gsub(' ','_')+'_'+test_case.gsub(' ','_')+'_index.html">' if @fail_statuses.include?(status) && total>0 tc_link='<a href="cases/1_'+@not_run_statuses.first.gsub(' ','_')+'_'+test_case.gsub(' ','_')+'_index.html">' if @not_run_statuses.include?(status) && total>0 else tc_link='<a href="'+result_page.to_i.to_s+'_chronological_total_run_index.html">' tc_link='<a href="1_reboot_index.html">' if status=="reboots" && total>0 tc_link='<a href="1_crash_index.html">' if status=="crashes" && total>0 tc_link='<a href="1_connection_errors_index.html">' if status=="connection_errors" && total>0 tc_link='<a href="1_'+@pass_statuses.first.gsub(' ','_')+'_'+test_case.gsub(' ','_')+'_index.html">' if @pass_statuses.include?(status) && total>0 tc_link='<a href="1_'+@fail_statuses.first.gsub(' ','_')+'_'+test_case.gsub(' ','_')+'_index.html">' if @fail_statuses.include?(status) && total>0 tc_link='<a href="1_'+@not_run_statuses.first.gsub(' ','_')+'_'+test_case.gsub(' ','_')+'_index.html">' if @not_run_statuses.include?(status) && total>0 end tc_link end |
#add_result_style_tag(status, total) ⇒ Object
268 269 270 271 272 273 274 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 268 def add_result_style_tag(status,total) tc_style_tag=' id=""' tc_style_tag=' id="passed_case"' if @pass_statuses.include?(status) && total>0 tc_style_tag=' id="failed_case"' if @fail_statuses.include?(status) && total>0 tc_style_tag=' id="not_run_case"' if @not_run_statuses.include?(status) && total>0 tc_style_tag end |
#collect_test_case_statistics ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 201 def collect_test_case_statistics() total_duration = 0.0 @group_test_case_arr.each do |test_case| tc_status=test_case[7] tc_name=test_case[0].to_s.gsub('_',' ') tc_execution=test_case[8].to_i reboots=test_case[2] crashes=test_case[3] tc_link=test_case[11] dump_count=test_case[13].to_i sent_bytes=test_case[14].to_i received_bytes=test_case[15].to_i memory_usage=test_case[6].to_i connection_errors=test_case[16].to_i duration=test_case[5].to_f total_duration = total_duration + duration b_test_in_statistics=false #Update total statistics update_total_execution_statistics(tc_status,reboots,crashes,connection_errors,dump_count,sent_bytes,received_bytes,memory_usage) #Update current test case total statistics b_test_in_statistics=update_test_case_execution_statistics(tc_name,tc_status,tc_execution,duration,tc_link,reboots,crashes,connection_errors,dump_count,sent_bytes,received_bytes,memory_usage) if b_test_in_statistics==false total_run=0 total_not_run=0 total_passed=0 @all_statuses.each do |status| if status==tc_status @statistics_arr << [tc_name,tc_status,1,tc_execution,tc_link] total_passed=1 if @pass_statuses.include?(tc_status) total_not_run=1 if @not_run_statuses.include?(tc_status) elsif status=="reboots" @statistics_arr << [tc_name,"reboots",reboots.to_i,tc_execution,tc_link] elsif status=="crashes" @statistics_arr << [tc_name,"crashes",crashes.to_i,tc_execution,tc_link] elsif status=="connection_errors" @statistics_arr << [tc_name,"connection_errors",connection_errors.to_i,tc_execution,tc_link] elsif status=="total" total_run=1 @statistics_arr << [tc_name,"total",1,tc_execution,tc_link] elsif status=="duration" @statistics_arr << [tc_name,"duration",duration,tc_execution,tc_link] elsif status=="dump count" @statistics_arr << [tc_name,"dump count",dump_count,tc_execution,tc_link] elsif status=="sent bytes" @statistics_arr << [tc_name,"sent bytes",sent_bytes,tc_execution,tc_link] elsif status=="received bytes" @statistics_arr << [tc_name,"received bytes",received_bytes,tc_execution,tc_link] elsif status=="used mem" @statistics_arr << [tc_name,"used mem",memory_usage,tc_execution,tc_link] elsif status=="pass rate" pass_rate=(total_passed.to_f/(total_run.to_f-total_not_run.to_f))*100 pass_rate="%0.2f" % pass_rate @statistics_arr << [tc_name,"pass rate",pass_rate,tc_execution,tc_link] else @statistics_arr << [tc_name,status,0,tc_execution,tc_link] end end end end end |
#generate_duration_graph(file_name) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 306 def generate_duration_graph(file_name) begin require 'gruff' rescue LoadError $stderr.puts "Can't load the Gruff gem. If its missing from your system please run 'gem install gruff' to install it." end reset_total_statistics() collect_test_case_statistics() begin labels = Hash.new durations = Array.new test_case_added=Array.new current_index = 0 @statistics_arr.each do |test_case| tc_name=test_case[0].to_s.gsub('_',' ') if test_case_added.include?(tc_name)==false && test_case[1].to_s=="duration" durations << test_case[2] labels[current_index] = "#{current_index + 1}" #tc_name current_index += 1 test_case_added << tc_name end end if current_index > 50 g = Gruff::SideStackedBar.new("400x#{15*current_index.to_i}") else g = Gruff::SideStackedBar.new() end g.title = "Duration Distribution" g.data("Duration", durations) g.labels = labels g.write(file_name) rescue Exception => e $stderr.puts "Can't load the Gruff gem. If its missing from your system please run 'gem install gruff' to install it." end end |
#generate_statistics_headers ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 61 def generate_statistics_headers() status_heads=Array.new @pass_statuses.each do |status| status_heads << "<th abbr=\"link_column\"><b>#{status}</b></th>" end @fail_statuses.each do |status| status_heads << "<th abbr=\"link_column\"><b>#{status}</b></th>" end @not_run_statuses.each do |status| status_heads << "<th abbr=\"link_column\"><b>#{status}</b></th>" end status_heads << "<th abbr=\"link_column\"><b>Reboots</b></th>" status_heads << "<th abbr=\"link_column\"><b>Crashes</b></th>" status_heads << "<th abbr=\"link_column\"><b>Connection Errors</b></th>" status_heads << "<th abbr=\"link_column\"><b>Duration</b></th>" status_heads << "<th abbr=\"link_column\"><b>Dump count</b></th>" status_heads << "<th abbr=\"link_column\"><b>Sent bytes</b></th>" status_heads << "<th abbr=\"link_column\"><b>Received bytes</b></th>" status_heads << "<th abbr=\"link_column\"><b>Used mem</b></th>" status_heads << "<th abbr=\"link_column\"><b>Pass %</b></th>" status_heads end |
#generate_statistics_table ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 345 def generate_statistics_table() table_body=Array.new reset_total_statistics() collect_test_case_statistics() table_body='<table id="statistics_table" class="sortable" align="center" border="0" cellspacing="0" style="width:100%;">'<< '<thead><tr>'<< '<th>'<< '<b>Row</b></th>'<< '<th abbr="link_column">'<< '<b>Name</b></th>'<< '<th abbr="link_column">'<< '<b>Total</b></th>'<< generate_statistics_headers.to_s << '</tr></thead><tbody>' test_case_added=Array.new row=1 @statistics_arr.each do |test_case| tc_name=test_case[0].to_s.gsub('_',' ') if @summary test_link="cases/#{test_case[4]}" else test_link=test_case[4] end if test_case_added.include?(tc_name)==false table_body << "<tr>" table_body << "<td>#{row}</td>" table_body << "<td><a href=\"#{test_link}\">#{tc_name}</a></td>" @statistics_arr.each do |test_case_statistics| if test_case_statistics[0]==tc_name table_body << "<td#{add_result_style_tag(test_case_statistics[1],test_case_statistics[2])}>#{add_result_link(test_case_statistics[0],test_case_statistics[1],test_case_statistics[2],test_case_statistics[3])}#{test_case_statistics[2]}</a></td>" end end table_body << "</tr>" test_case_added << tc_name row+=1 end end table_body << '</tbody>' table_body << '<tfoot><tr>' << '<td></td><td>'<< '<b>Total</b></td>' @total_statistics_arr.each do |statistic| table_body << "<td><b>#{statistic[1]}</b></td>" end table_body << '</tr></tfoot>' << '</table>' table_body end |
#reset_total_statistics ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 34 def reset_total_statistics() @all_statuses << "total" @total_statistics_arr << ["total",0] @pass_statuses.each do |status| @total_statistics_arr << [status,0] @all_statuses << status end @fail_statuses.each do |status| @total_statistics_arr << [status,0] @all_statuses << status end @not_run_statuses.each do |status| @total_statistics_arr << [status,0] @all_statuses << status end @total_statistics_arr << ["reboots",0] @total_statistics_arr << ["crashes",0] @total_statistics_arr << ["connection_errors",0] @total_statistics_arr << ["duration",0] @total_statistics_arr << ["dump count",0] @total_statistics_arr << ["sent bytes",0] @total_statistics_arr << ["received bytes",0] @total_statistics_arr << ["used mem",0] @total_statistics_arr << ["pass rate",0] @all_statuses << "reboots" << "crashes" << "connection_errors" << "duration" << "dump count" << "sent bytes" << "received bytes" << "used mem" << "pass rate" end |
#update_test_case_execution_statistics(tc_name, tc_status, tc_execution, duration, tc_link, reboots, crashes, connection_errors, dump_count, sent_bytes, received_bytes, memory_usage) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 124 def update_test_case_execution_statistics(tc_name,tc_status,tc_execution,duration,tc_link,reboots,crashes,connection_errors,dump_count,sent_bytes,received_bytes,memory_usage) b_test_in_statistics=false current_index=0 total_run=0 total_not_run=0 total_passed=0 total_not_run_index=0 total_passed_index=0 pass_rate_index=0 @statistics_arr.each do |total_status| if total_status[1]==tc_status && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,tc_status,total_status[2].to_i+1,tc_execution,tc_link] end if total_status[1]=="reboots" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"reboots",total_status[2].to_i+reboots.to_i,tc_execution,tc_link] end if total_status[1]=="crashes" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"crashes",total_status[2].to_i+crashes.to_i,tc_execution,tc_link] end if total_status[1]=="connection_errors" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"connection_errors",total_status[2].to_i+connection_errors.to_i,tc_execution,tc_link] end if total_status[1]=="total" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"total",total_status[2].to_i+1,tc_execution,tc_link] total_run=total_status[2].to_i+1 end if total_status[1]=="duration" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"duration",duration,tc_execution,tc_link] end if total_status[1]=="dump count" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"dump count",total_status[2].to_i+dump_count.to_i,tc_execution,tc_link] end if total_status[1]=="sent bytes" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"sent bytes",total_status[2].to_i+sent_bytes.to_i,tc_execution,tc_link] end if total_status[1]=="received bytes" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"received bytes",total_status[2].to_i+received_bytes.to_i,tc_execution,tc_link] end if total_status[1]=="used mem" && total_status[0]==tc_name b_test_in_statistics=true @statistics_arr[current_index]=[tc_name,"used mem",total_status[2].to_i,tc_execution,tc_link] end if total_status[1]=="pass rate" && total_status[0]==tc_name b_test_in_statistics=true pass_rate_index=current_index end if @pass_statuses.include?(total_status[1]) && total_status[0]==tc_name total_passed_index=current_index end if @not_run_statuses.include?(total_status[1]) && total_status[0]==tc_name total_not_run_index=current_index end current_index+=1 end if b_test_in_statistics==true total_passed_result=@statistics_arr[total_passed_index] total_not_run_result=@statistics_arr[total_not_run_index] total_passed=total_passed_result[2].to_i total_not_run=total_not_run_result[2].to_i pass_rate=(total_passed.to_f/(total_run.to_f-total_not_run.to_f))*100 pass_rate="%0.2f" % pass_rate @statistics_arr[pass_rate_index]=[tc_name,"pass rate",pass_rate,tc_execution,tc_link] end b_test_in_statistics end |
#update_total_execution_statistics(tc_status, reboots, crashes, connection_errors, dump_count, sent_bytes, received_bytes, memory_usage) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tdriver/report/report_execution_statistics.rb', line 84 def update_total_execution_statistics(tc_status,reboots,crashes,connection_errors,dump_count,sent_bytes,received_bytes,memory_usage) current_index=0 @total_statistics_arr.each do |total_status| if tc_status==total_status[0] @total_statistics_arr[current_index]=[tc_status,total_status[1].to_i+1] end if total_status[0]=="reboots" @total_statistics_arr[current_index]=["reboots",total_status[1].to_i+reboots.to_i] end if total_status[0]=="crashes" @total_statistics_arr[current_index]=["crashes",total_status[1].to_i+crashes.to_i] end if total_status[0]=="connection_errors" @total_statistics_arr[current_index]=["connection_errors",total_status[1].to_i+connection_errors.to_i] end if total_status[0]=="total" @total_statistics_arr[current_index]=["total",total_status[1].to_i+1] end if total_status[0]=="duration" @total_statistics_arr[current_index]=["duration",""] end if total_status[0]=="dump count" @total_statistics_arr[current_index]=["dump count",total_status[1].to_i+dump_count.to_i] end if total_status[0]=="sent bytes" @total_statistics_arr[current_index]=["sent bytes",total_status[1].to_i+sent_bytes.to_i] end if total_status[0]=="received bytes" @total_statistics_arr[current_index]=["received bytes",total_status[1].to_i+received_bytes.to_i] end if total_status[0]=="used mem" @total_statistics_arr[current_index]=["used mem",""] end if total_status[0]=="pass rate" @total_statistics_arr[current_index]=["pass rate",""] end current_index+=1 end end |