Class: TestRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/java_autotest/test_runner.rb

Constant Summary collapse

ICON =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'img', 'java_icon.png'))
Title =
'Java AutoTest'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestRunner

Returns a new instance of TestRunner.



10
11
12
# File 'lib/java_autotest/test_runner.rb', line 10

def initialize
  @build_tool = discover_build_tool
end

Instance Attribute Details

#build_toolObject

Returns the value of attribute build_tool.



2
3
4
# File 'lib/java_autotest/test_runner.rb', line 2

def build_tool
  @build_tool
end

Class Method Details

.valid_toolsObject



6
7
8
# File 'lib/java_autotest/test_runner.rb', line 6

def self.valid_tools
  %w(mvn gradle)
end

Instance Method Details

#discover_build_toolObject



14
15
16
# File 'lib/java_autotest/test_runner.rb', line 14

def discover_build_tool
  File.exists?("build.gradle") ? "gradle" : "mvn" 
end

#notify(message) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/java_autotest/test_runner.rb', line 31

def notify(message)
  case RUBY_PLATFORM
  when /darwin/
    system "growlnotify -t '#{Title}' -m '#{message}' --image #{ICON}"
  when /linux/
    system "notify-send '#{Title}' '#{message}' --icon #{ICON}"
  end
end

#run_all_testsObject



25
26
27
28
29
# File 'lib/java_autotest/test_runner.rb', line 25

def run_all_tests
  green = system("#{@build_tool} test")
  notify "Build Success" if green
  notify "Build Broken" unless green 
end

#run_test(test_class) ⇒ Object



18
19
20
21
22
23
# File 'lib/java_autotest/test_runner.rb', line 18

def run_test(test_class)
  command = ".single" if @build_tool == "gradle"
  green = system("#{@build_tool} -Dtest#{command}=#{test_class} test")
  notify "Test Failure: #{test_class}" unless green
  green
end