Class: Buildr::JUnit
- Inherits:
-
TestFramework::Java
- Object
- TestFramework::Base
- TestFramework::Java
- Buildr::JUnit
- Defined in:
- lib/buildr/java/tests.rb
Overview
JUnit test framework, the default test framework for Java tests.
Support the following options:
-
:fork – If true/:once (default), fork for each test class. If :each, fork for each individual
test case. If false, run all tests in the same VM (fast, but dangerous).
-
:clonevm – If true clone the VM each time it is forked.
-
:properties – Hash of system properties available to the test case.
-
:environment – Hash of environment variables available to the test case.
-
:java_args – Arguments passed as is to the JVM.
Defined Under Namespace
Classes: Report
Constant Summary collapse
- VERSION =
JUnit version number.
'4.11'
Instance Attribute Summary
Attributes inherited from TestFramework::Base
Class Method Summary collapse
-
.ant_taskdef ⇒ Object
:nodoc:.
- .dependencies ⇒ Object
-
.report ⇒ Object
:call-seq: report().
- .version ⇒ Object
Instance Method Summary collapse
-
#run(tests, dependencies) ⇒ Object
:nodoc:.
-
#tests(dependencies) ⇒ Object
:nodoc:.
Methods inherited from TestFramework::Java
Methods inherited from TestFramework::Base
applies_to?, #dependencies, #initialize, to_sym
Constructor Details
This class inherits a constructor from Buildr::TestFramework::Base
Class Method Details
.ant_taskdef ⇒ Object
:nodoc:
198 199 200 |
# File 'lib/buildr/java/tests.rb', line 198 def ant_taskdef #:nodoc: "org.apache.ant:ant-junit:jar:#{Ant.version}" end |
.dependencies ⇒ Object
193 194 195 196 |
# File 'lib/buildr/java/tests.rb', line 193 def dependencies four11_or_newer = version >= '4.11' @dependencies ||= ["junit:junit:jar:#{version}"]+ (four11_or_newer ? JMock.dependencies({:hamcrest => '1.3'}) : JMock.dependencies) end |
Instance Method Details
#run(tests, dependencies) ⇒ Object
:nodoc:
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 |
# File 'lib/buildr/java/tests.rb', line 215 def run(tests, dependencies) #:nodoc: # Use Ant to execute the Junit tasks, gives us performance and reporting. Buildr.ant('junit') do |ant| case [:fork] when false forking = {} when :each forking = { :fork=>true, :forkmode=>'perTest' } when nil, true, :once forking = { :fork=>true, :forkmode=>'once' } else fail 'Option fork must be :once, :each or false.' end mkpath task.report_to.to_s taskdef = Buildr.artifact(JUnit.ant_taskdef) taskdef.invoke ant.taskdef :name=>'junit', :classname=>'org.apache.tools.ant.taskdefs.optional.junit.JUnitTask', :classpath=>taskdef.to_s ant.junit forking.merge(:clonevm=> !![:clonevm], :dir=>task.send(:project).path_to) do ant.classpath :path=>dependencies.join(File::PATH_SEPARATOR) ([:properties] || []).each { |key, value| ant.sysproperty :key=>key, :value=>value } ([:environment] || []).each { |key, value| ant.env :key=>key, :value=>value } Array([:java_args]).each { |value| ant.jvmarg :value=>value } ant.formatter :type=>'plain' ant.formatter :type=>'plain', :usefile=>false # log test ant.formatter :type=>'xml' ant.batchtest :todir=>task.report_to.to_s, :failureproperty=>'failed' do ant.fileset :dir=>task.compile.target.to_s do tests.each { |test| ant.include :name=>File.join(*test.split('.')).ext('class') } end end end return tests unless ant.project.getProperty('failed') end # But Ant doesn't tell us what went kaput, so we'll have to parse the test files. tests.inject([]) do |passed, test| report_file = File.join(task.report_to.to_s, "TEST-#{test}.txt") if File.exist?(report_file) report = File.read(report_file) # The second line (if exists) is the status line and we scan it for its values. status = (report.split("\n")[1] || '').scan(/(run|failures|errors):\s*(\d+)/i). inject(Hash.new(0)) { |hash, pair| hash[pair[0].downcase.to_sym] = pair[1].to_i ; hash } passed << test if status[:failures] == 0 && status[:errors] == 0 end passed end end |
#tests(dependencies) ⇒ Object
:nodoc:
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/buildr/java/tests.rb', line 203 def tests(dependencies) #:nodoc: if (self.class.version.to_s[0,1].to_i < 4) filter_classes(dependencies, :interfaces => %w{junit.framework.TestCase}) else filter_classes(dependencies, :interfaces => %w{junit.framework.TestCase}, :class_annotations => %w{org.junit.runner.RunWith}, :method_annotations => %w{org.junit.Test}) end end |