Class: Buildr::TestNG

Inherits:
Buildr::TestFramework::Java show all
Defined in:
lib/buildr/java/tests.rb

Overview

TestNG test framework. To use in your project:

test.using :testng

Support the following options:

  • :properties – Hash of properties passed to the test suite.

  • :java_args – Arguments passed to the JVM.

  • :args – Arguments passed to the TestNG command line runner.

Constant Summary collapse

VERSION =
'6.11'

Instance Attribute Summary

Attributes inherited from Buildr::TestFramework::Base

#options, #task

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Buildr::TestFramework::Java

applies_to?

Methods inherited from Buildr::TestFramework::Base

applies_to?, #dependencies, #initialize, to_sym

Constructor Details

This class inherits a constructor from Buildr::TestFramework::Base

Class Method Details

.dependenciesObject



293
294
295
296
# File 'lib/buildr/java/tests.rb', line 293

def dependencies
  return ["org.testng:testng:jar:jdk15:#{version}"] + JMock.dependencies if version < '6.0'
  ["org.testng:testng:jar:#{version}",'com.beust:jcommander:jar:1.27'] + JMock.dependencies
end

.versionObject



289
290
291
# File 'lib/buildr/java/tests.rb', line 289

def version
  Buildr.settings.build['testng'] || VERSION
end

Instance Method Details

#run(tests, dependencies) ⇒ Object

:nodoc:



305
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
344
# File 'lib/buildr/java/tests.rb', line 305

def run(tests, dependencies) #:nodoc:
  cmd_args = []
  cmd_args << '-suitename' << task.project.id
  cmd_args << '-sourcedir' << task.compile.sources.join(';') if TestNG.version < '6.0'
  cmd_args << '-log' << '2'
  cmd_args << '-d' << task.report_to.to_s
  exclude_args = options[:excludegroups] || []
  if !exclude_args.empty?
    cmd_args << '-excludegroups' << exclude_args.join(',')
  end
  groups_args = options[:groups] || []
  if !groups_args.empty?
    cmd_args << '-groups' << groups_args.join(',')
  end
  # run all tests in the same suite
  cmd_args << '-testclass' << (TestNG.version < '6.0' ? test : tests.join(','))

  cmd_args += options[:args] if options[:args]

  cmd_options = { :properties=>options[:properties], :java_args=>options[:java_args],
    :classpath=>dependencies, :name => "TestNG in #{task.send(:project).name}" }

  tmp = nil
  begin
    tmp = Tempfile.open('testNG')
    tmp.write cmd_args.join("\n")
    tmp.close
    Java::Commands.java ['org.testng.TestNG', "@#{tmp.path}"], cmd_options
    return tests
  rescue
    # testng-failed.xml contains the list of failed tests *only*
    report = File.read(File.join(task.report_to.to_s, 'testng-failed.xml'))
    failed = report.scan(/<class name="(.*?)">/im).flatten
    error "TestNG regexp returned unexpected failed tests #{failed.inspect}" unless (failed - tests).empty?
    # return the list of passed tests
    return tests - failed
  ensure
    tmp.close unless tmp.nil?
  end
end

#tests(dependencies) ⇒ Object

:nodoc:



299
300
301
302
303
# File 'lib/buildr/java/tests.rb', line 299

def tests(dependencies) #:nodoc:
  filter_classes(dependencies,
                 :class_annotations => %w{org.testng.annotations.Test},
                 :method_annotations => %w{org.testng.annotations.Test})
end