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.



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

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.



137
138
139
# File 'lib/buildr/java/tests.rb', line 137

def frames
  @frames
end

#paramsObject (readonly)

Parameters passed to the Ant JUnitReport task.



135
136
137
# File 'lib/buildr/java/tests.rb', line 135

def params
  @params
end

#style_dirObject

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



139
140
141
# File 'lib/buildr/java/tests.rb', line 139

def style_dir
  @style_dir
end

#targetObject

Target directory for generated report.



141
142
143
# File 'lib/buildr/java/tests.rb', line 141

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.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/buildr/java/tests.rb', line 155

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