Class: TDRunner::Main

Inherits:
Object
  • Object
show all
Includes:
TDRunnerMonitor
Defined in:
lib/tdrunner.rb

Overview

Main class which is used to start TDRunner run

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TDRunnerMonitor

#add_failed_testunit_tests, #add_missing_methods, #add_missing_methods_in_to_test_class, #add_tcs_to_failed_array, #exit_tdrunner_execution, #find_missing_method_from_ruby_file, #flatten_tests, #format_duration, #format_execution_duration, #get_missing_methods, #get_pos_string, #get_test_class, #get_test_classes, #get_test_name, #is_class_included, #order_the_features, #order_the_tests, #organize_features, #organize_tests, #randomize_features, #randomize_test_cases, #record_test_to_recorder_profile, #remove_extra_ends_from_implementation, #tdrunner_active, #trap_interrupt, #trap_pause, #value_exists_in_array, #wait_for_starttime, #write_failed_sip_file, #write_recorded_sip_file

Constructor Details

#initialize(args) ⇒ Main

Initializes TDRunner and checks the command line parameters -h and –help displays help for TDRunner -p loads a execution profile from siearra.yml configuration file form config folder in the execution directory parse the command line arguments if above steps are not found



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
# File 'lib/tdrunner.rb', line 46

def initialize(args)

  if args.empty?
    tdrunner_help()
    return
  end

  verbose = 0

  while true

    if args[0]=='--display'
      args.shift
      ENV['DISPLAY'] = args.shift

    elsif args[0]=='-h' or args[0]=='--help'
      args.shift
      tdrunner_help()

    elsif args[0]=='--cd'
      args.shift
      Dir.chdir(args.shift)

    elsif args[0]=='--verbose'
      args.shift
      verbose += 1

    elsif args[0]=='--version'
      args.shift
      puts '1.5.2'

    else
      break
    end
  end

  if verbose > 0
    puts "DISPLAY=#{ENV['DISPLAY']}"
    puts "PWD=#{Dir.pwd()}"
  end

  if args.empty?
    tdrunner_help()

  elsif args[0]=='--websi'
    start_websi(args[1, args.size])

  elsif args[0]=='--cmd'
    tool = TDRunnerCommandTool.new(args[1, args.size])

  elsif args[0]=='-p'
    profile = TDRunnerProfileLoader.new(args)
    tdrunner_profiles=profile.get_execution_profiles
    tdrunner_profiles.each do |tdrunner_profile|
      tdrunner_profile_execution_args=profile.args_from(tdrunner_profile)
      start_tdrunner(tdrunner_profile_execution_args)
    end

  else
    start_tdrunner(args)
  end

end

Class Method Details

.execute(args) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/tdrunner.rb', line 33

def execute(args)
  begin
    new(args)
    return 0
  rescue Exception => e
    Kernel.raise e,("#{e.message} #{e.backtrace}")
  end
end

Instance Method Details

#execute_cucumber_tests(test_parameters = []) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/tdrunner.rb', line 148

def execute_cucumber_tests(test_parameters=[])
  if Gem.available?('cucumber')
    @cucumber_command=Array.new(test_parameters)
    @tdrunner_runner=TDRunnerCucumber::ForkedCucumberRunner.new(@cucumber_command).execute
  else
    puts('WARNING: Cucumber test framework gem was not found or installed')
  end
end

#execute_test_unit_tests(test_parameters) ⇒ Object

Executes the tdrunner command Loads the tdrunner command parameters in to memory for test execution control



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/tdrunner.rb', line 129

def execute_test_unit_tests(test_parameters)
  test_files=[]
  tests=[]
  test_suite = Test::Unit::TestSuite.new('Test suite')
  tdrunner_tests=TDRunnerTestUnit::TDRunnerTestSuiteBuilder.new()
  test_parameters.each do |value|
    test_files.push tdrunner_tests.get_files(value)
  end
  test_files.each do |test_file|
    tests.push tdrunner_tests.add_file(test_file)
  end
  tests.each do |test_classes|
    test_classes.each do |test_class|
      test_suite << test_class.suite
    end
  end
  @tdrunner_runner=TDRunnerTestUnit::ForkedTestUnitRunner.new(test_suite)
end

#start_tdrunner(args) ⇒ Object



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
# File 'lib/tdrunner.rb', line 157

def start_tdrunner(args)
  $tdrunner_parameters=TDRunnerParameters.new(args)
  ARGV.clear
  wait_for_starttime($tdrunner_parameters)
  case $tdrunner_parameters.test_framework
  when 'cucumber'
    require File.expand_path( File.join( File.dirname( __FILE__ ), 'tdrunner_cucumber' ) )
    @cucumber_command=$tdrunner_parameters.test_framework_command
    execute_cucumber_tests(@cucumber_command)
  when 'test_suite', 'test_unit'
    require File.expand_path( File.join( File.dirname( __FILE__ ), 'tdrunner_test_unit' ) )
    @test_unit_command=$tdrunner_parameters.test_framework_command
    execute_test_unit_tests(@test_unit_command)
  else
    require File.expand_path( File.join( File.dirname( __FILE__ ), 'tdrunner_cucumber' ) )
    require File.expand_path( File.join( File.dirname( __FILE__ ), 'tdrunner_test_unit' ) )
    @test_folder=$tdrunner_parameters.test_framework_command
    execute_test_unit_tests(@test_folder)
    @test_folder.each do |folder|
      if File.directory?(folder)
        if Gem.available?('cucumber')
          if Gem.available?('cucumber','=0.4.4')
            cucumber_parameters=["#{folder.to_s}", "-f", "TDriverReport::CucumberListener"]
          end
          if Gem.available?('cucumber','>0.4.4')
            cucumber_parameters=["#{folder.to_s}", "-f", "TDriverReport::CucumberReporter"]
          end
          execute_cucumber_tests(cucumber_parameters)
        else
          puts('WARNING: Cucumber test framework gem was not found or installed')
        end
      end
    end
  end

  write_failed_sip_file($tdrunner_parameters)
  write_recorded_sip_file($tdrunner_parameters)
end

#start_websi(args = []) ⇒ Object

Start tdrunner web UI



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/tdrunner.rb', line 111

def start_websi(args=[])
  websi_dir=[]
  tdrunner_location=File.dirname(__FILE__)
  websi_dir_arr=tdrunner_location.split('/')
  for i in (0..websi_dir_arr.length-4)
    websi_dir << websi_dir_arr[i] if websi_dir_arr[i] != nil
  end
  websi_path=websi_dir.join('/')
  begin
    Dir.chdir(websi_path+'/websi')
    system("ruby", "script/server", *args)
  rescue
  ensure
  end
end

#tdrunner_helpObject

Method for displaying tdrunner help in commandline



197
198
199
200
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
267
268
269
270
271
272
273
274
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
305
306
# File 'lib/tdrunner.rb', line 197

def tdrunner_help()
  puts 'Usage: tdrunner [runner opts] [--websi opts|--cmd opts|test opts] [command]'
  puts ''
  puts 'Examples:'
  puts ''
  puts 'Execute tests in my_test_folder:'
  puts 'tdrunner my_test_folder'
  puts ''
  puts 'Execute tests for 1.5 hours:'
  puts 'tdrunner -H 1.5 cucumber features'
  puts 'tdrunner -H 1.5 test_suite ts_my_test_unit_suite.rb'
  puts ''
  puts 'Repeat tests for ten iterations:'
  puts 'tdrunner -i 10 cucumber features'
  puts 'tdrunner -i 10 test_suite ts_my_test_unit_suite.rb'
  puts ''
  puts 'Run tests until defined date and time is reached:'
  puts 'tdrunner -d "12.12.2100 12:00" cucumber features'
  puts 'tdrunner -d "12.12.2100 12:00" test_suite ts_my_test_unit_suite.rb'
  puts ''
  puts 'Start tests when this time is reached:'
  puts 'tdrunner -s "12.12.2100 12:00" cucumber features'
  puts 'tdrunner -s "12.12.2100 12:00" test_suite ts_my_test_unit_suite.rb'
  puts ''
  puts 'Run test unit teardown only when the testcase is failed:'
  puts 'tdrunner --teardown -d "12.12.2100 12:00" test_suite ts_my_test_unit_suite.rb'
  puts ''
  puts 'Create a execution profile without running the tests:'
  puts 'tdrunner -m my_execution_profile --teardown -d "12.12.2100 12:00" test_suite ts_my_test_unit_suite.rb'
  puts 'tdrunner -m my_execution_profile my_test_case_folder'
  puts ''
  puts 'Run tests using a execution profile:'
  puts 'tdrunner -e my_execution_profile --teardown -d "12.12.2100 12:00" test_suite ts_my_test_unit_suite.rb'
  puts 'tdrunner -e my_execution_profile my_test_folder'
  puts 'tdrunner --ordered -e my_execution_profile my_test_folder'
  puts ''
  puts 'Create a execution profile of all Test::Unit tests which failed when tests were'
  puts 'run using an execution profile:'
  puts 'tdrunner -t my_failed_test_cases.sip -e my_execution_profile my_test_case_folder'
  puts ''
  puts 'Runs tests using a predefined profiles:'
  puts 'tdrunner -p lpt'
  puts 'tdrunner -p lpt_qt lpt_sd my_cucumber_tests my_test_unit_test'
  puts ''
  puts 'Combines prefious test results to the current test execution:'
  puts 'tdrunner -c C:/tdriver_reports/test_run_yyyyddmmhhss my_test_suite_folder'
  puts ''
  puts ''

  puts "Runner options:"
  puts ''

  puts "--cd directory\tSet working directory, useful when invoking tdrunner remotely"

  puts "--display display\tSet DISPLAY environment variable, useful for testing"
  puts "\t\tdesktop applications remotely"

  puts "-h, --help\tYou're looking at it."

  puts "--verbose\tPrint extra information"

  puts "--version\tShow version."

  puts ''
  puts ''
  puts "--cmd sut sut_id httpd server_port [usb powerup|powerdown|reset] [status]"
  puts "\t\tProbe status of given sut and given httpd server."
  puts "\t\t(Used by tdrunner_ui.)"
  puts "--cmd sut sut_id usb powerup|powerdown|reset"
  puts "\t\tPerform given usb command using given sut."
  puts "\t\t(Used by tdrunner_ui.)"
  puts ''
  puts ''
  puts "--websi [optional arguments]"
  puts "\t\tStarts tdrunner web interface, by default at URL"
  puts "\t\thttp://localhost:3000/websi/"
  puts ''
  puts ''
  puts "Test options:"
  puts ''

  puts "-H i\t\tDefines how many hours tdrunner will run i as number of hours."

  puts "-i i\t\tDefines how many iterations tdrunner will run the tests i as"
  puts "\t\tnumber of iterations."

  puts "-d \"date time\"\tDefines end date and time when tdrunner will stop testing"

  puts "-e execution_profile"
  puts "\t\tUse execution profile for running tests"

  puts "-m execution_profile"
  puts "\t\tCreate execution profile without running tests"

  puts "-t execution_profile"
  puts "\t\tCreate execution profile of failed Test::Unit tests"

  puts "-r execution_profile"
  puts "\t\tCreate execution profile recording of executed tests"
  
  puts "--teardown\tRun test unit teardown only when the testcase is failed."

  puts "--ordered\tUse with execution profile to run tests as they are ordered"
  puts "\t\tin the sip file."

  puts "-p profile_name\tPull commandline arguments from tdrunner.yml which can be"
  puts "\t\tdefined as strings or arrays."


end