Class: Buildr::JUnit::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/buildr/java/tests.rb

Overview

Used by the junit:report task. Access through JUnit#report if you want to set various options for that task, for example:

JUnit.report.frames = false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



152
153
154
155
156
# File 'lib/buildr/java/tests.rb', line 152

def initialize
  @params = {}
  @frames = true
  @target = 'reports/junit'
end

Instance Attribute Details

#framesObject

True (default) to produce a report using frames, false to produce a single-page report.



146
147
148
# File 'lib/buildr/java/tests.rb', line 146

def frames
  @frames
end

#paramsObject (readonly)

Parameters passed to the Ant JUnitReport task.



144
145
146
# File 'lib/buildr/java/tests.rb', line 144

def params
  @params
end

#style_dirObject

Directory for the report style (defaults to using the internal style).



148
149
150
# File 'lib/buildr/java/tests.rb', line 148

def style_dir
  @style_dir
end

#targetObject

Target directory for generated report.



150
151
152
# File 'lib/buildr/java/tests.rb', line 150

def target
  @target
end

Instance Method Details

#generate(projects, target = @target.to_s) ⇒ Object

:call-seq:

generate(projects, target?)

Generates a JUnit report for these projects (must run JUnit tests first) into the target directory. You can specify a target, or let it pick the default one from the target attribute.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/buildr/java/tests.rb', line 164

def generate(projects, target = @target.to_s)
  html_in = File.join(target, 'html')
  rm_rf html_in ; mkpath html_in

  Buildr.ant('junit-report') do |ant|
    ant.taskdef :name=>'junitreport', :classname=>'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
      :classpath=>Buildr.artifacts(JUnit.ant_taskdef).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
    ant.junitreport :todir=>target do
      projects.select { |project| project.test.framework == :junit }.
        map { |project| project.test.report_to.to_s }.select { |path| File.exist?(path) }.
        each { |path| ant.fileset(:dir=>path) { ant.include :name=>'TEST-*.xml' }  }
      options = { :format=>frames ? 'frames' : 'noframes' }
      options[:styledir] = style_dir if style_dir
      ant.report options.merge(:todir=>html_in) do
        params.each { |key, value| ant.param :name=>key, :expression=>value }
      end
    end
  end
end