lib/java/test.rb in buildr-1.2.3 vs lib/java/test.rb in buildr-1.2.4

- old
+ new

@@ -140,11 +140,11 @@ # List of supported test framework, first one being a default. Test frameworks are added by # including them in TestTask (e.g. JUnit, TestNG). TEST_FRAMEWORKS = [] # Default options already set on each test task. - DEFAULT_OPTIONS = { :fail_on_failure=>true } + DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{} } # JMock version.. JMOCK_VERSION = "1.2.0" # JMock specification. JMOCK_REQUIRES = "jmock:jmock:jar:#{JMOCK_VERSION}" @@ -157,11 +157,11 @@ def initialize(*args) #:nodoc: super @classpath = [] @include = [] @exclude = [] - parent = Rake::Task["^test"] if name[":"] # Only if in namespace + parent = Project.task_in_parent_project(name) @options = parent && parent.respond_to?(:options) ? parent.options.clone : DEFAULT_OPTIONS.clone enhance { run_tests } end def execute() #:nodoc: @@ -249,19 +249,25 @@ # :call-seq: # using(options) => self # # Sets various test options and returns self. Accepts a hash of options, or symbols (a symbol sets that # option to true). For example: - # test.using :testng, :properties=>{ "url"=>"http://localhost:8080" } + # test.using :testng, :fork=>:each, :properties=>{ "url"=>"http://localhost:8080" } # # Currently supports the following options: - # * :properties -- System properties. - # * :java_args -- Java arguments when forking a new JVM. # * :fail_on_failure -- True to fail on test failure (default is true). + # * :fork -- Fork test cases (JUnit only). + # * :java_args -- Java arguments when forking a new JVM. + # * :properties -- System properties. + # + # The :fork option takes the following values: + # * :once -- Fork one JVM for each project (default). + # * :each -- Fork one JVM for each test case. + # * false -- Do not fork, running all test cases in the same JVM. def using(*args) - args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last - args.each { |key| @options[key.to_sym] = true } + args.pop.each { |key, value| options[key.to_sym] = value } if Hash === args.last + args.each { |key| options[key.to_sym] = true } self end # :call-seq: # include(*classes) => self @@ -465,13 +471,25 @@ def junit_run(args) rm_rf report_to.to_s ; mkpath report_to.to_s # Use Ant to execute the Junit tasks, gives us performance and reporting. Buildr.ant("junit") do |ant| - ant.junit :printsummary=>"withOutAndErr" do + case options[:fork] + when false + forking = {} + when :each + forking = { :fork=>true, :forkmode=>"perTest" } + when true, :once + forking = { :fork=>true, :forkmode=>"once" } + else + fail "Option fork must be :once, :each or false." + end + ant.junit forking do ant.classpath :path=>args[:classpath].map(&:to_s).each { |path| file(path).invoke }.join(File::PATH_SEPARATOR) args[:properties].each { |key, value| ant.sysproperty :key=>key, :value=>value } ant.formatter :type=>"plain" + ant.formatter :type=>"xml" + ant.formatter :type=>"plain", :usefile=>false # log test ant.formatter :type=>"xml" ant.batchtest :todir=>report_to.to_s, :failureproperty=>"failed" do ant.fileset :dir=>compile.target.to_s do args[:classes].each { |cls| ant.include :name=>cls.gsub(".", "/").ext("class") } end