Class: Raven::JUnitTask

Inherits:
JavacTask
  • Object
show all
Defined in:
lib/raven/java_tasks.rb

Overview

The JUnit task runs all your test cases located in src/test/java or the build_path that you can set. JUnit inherits from the JavacTask so it accepts every configuration that JavacTask accepts. In addition you can add a pattern for your test classes (default pattern is **/Test*.java).

Instance Method Summary collapse

Methods inherited from JavacTask

#build_path, #build_path=

Instance Method Details

#executeObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/raven/java_tasks.rb', line 96

def execute
  @build_path = ["src/test/java"] unless @build_path
  super
  pattern = (@test_classes.nil? || @test_classes.empty?) ? "**/Test*.java" : @test_classes.first
  tests = @build_path.collect { |d| Dir.glob("#{d}/#{pattern}").collect { |sd| sd[d.size+1..-1] } }
  @test_classes = tests.flatten.collect { |d| d.gsub('/', '.')[0..-6] }
  failures = false
  @test_classes.flatten.each do |tc|
    puts "Running test #{tc}"
    result = `java -classpath "#{@classpath.join(CP_SEP)}" junit.textui.TestRunner #{tc}`
    puts result
    failures = true if /FAILURES/ =~ result || /ERRORS/ =~ result
  end
  if failures
    puts "There were failures!"
    exit(1)
  end
end

#test_classesObject



115
116
117
# File 'lib/raven/java_tasks.rb', line 115

def test_classes
  @test_classes ||= []
end

#test_classes=(c) ⇒ Object



119
120
121
# File 'lib/raven/java_tasks.rb', line 119

def test_classes=(c)
  @test_classes = [c]
end