java-autotest 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/{README.rdoc → README.textile} +22 -13
- data/VERSION.yml +1 -1
- data/bin/java-autotest +1 -0
- data/img/java_icon.png +0 -0
- data/java-autotest.gemspec +8 -5
- data/lib/java_autotest.rb +12 -18
- data/lib/java_autotest/autotest.rb +34 -32
- data/lib/java_autotest/test_runner.rb +38 -7
- data/spec/java_autotest/autotest_spec.rb +26 -24
- data/spec/java_autotest/file_spec.rb +13 -13
- data/spec/java_autotest/test_runner_spec.rb +101 -10
- data/spec/java_autotest_spec.rb +4 -0
- metadata +9 -6
@@ -1,17 +1,28 @@
|
|
1
|
-
|
1
|
+
h2. Java AutoTest
|
2
2
|
|
3
3
|
Instant feedback for yours tests.
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
h2. Installation
|
6
|
+
|
7
|
+
gem install java-autotest
|
8
|
+
|
9
|
+
h2. Dependencies
|
7
10
|
|
8
|
-
== Dependencies
|
9
11
|
Ensures that you already have installed:
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
* Java
|
14
|
+
* Maven 2 or Gradle
|
15
|
+
|
16
|
+
h2. On OS X:
|
17
|
+
|
18
|
+
* "Growl":http://growl.info
|
19
|
+
* "growlnotify":http://growl.info/extras.php#growlnotify
|
20
|
+
|
21
|
+
h2. On Ubuntu:
|
22
|
+
|
23
|
+
* "libnotify-bin":http://packages.ubuntu.com/lucid/libnotify-bin
|
13
24
|
|
14
|
-
|
25
|
+
h2. How its works
|
15
26
|
|
16
27
|
* Find all java files inside src folder.
|
17
28
|
* Run all tests.
|
@@ -19,13 +30,11 @@ Ensures that you already have installed:
|
|
19
30
|
* Run modified test.
|
20
31
|
* All green? run all testes
|
21
32
|
|
22
|
-
|
23
|
-
java-autotest at the project root folder.
|
33
|
+
h2. Usage
|
24
34
|
|
25
|
-
|
26
|
-
- Ant, Ivy and gralde suppport.
|
35
|
+
java-autotest at the project root folder.
|
27
36
|
|
28
|
-
|
37
|
+
h2. Note on Patches/Pull Requests
|
29
38
|
|
30
39
|
* Fork the project.
|
31
40
|
* Make your feature addition or bug fix.
|
@@ -35,6 +44,6 @@ Ensures that you already have installed:
|
|
35
44
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
36
45
|
* Send me a pull request. Bonus points for topic branches.
|
37
46
|
|
38
|
-
|
47
|
+
h2. Copyright
|
39
48
|
|
40
49
|
Copyright (c) 2010 rodolfoliviero. See LICENSE for details.
|
data/VERSION.yml
CHANGED
data/bin/java-autotest
CHANGED
data/img/java_icon.png
ADDED
Binary file
|
data/java-autotest.gemspec
CHANGED
@@ -5,18 +5,18 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{java-autotest}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["rodolfoliviero"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-30}
|
13
13
|
s.default_executable = %q{java-autotest}
|
14
14
|
s.description = %q{Java AutoTest}
|
15
15
|
s.email = %q{rodolfoliviero@gmail.com}
|
16
16
|
s.executables = ["java-autotest"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
"README.
|
19
|
+
"README.textile"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
@@ -24,10 +24,11 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Gemfile",
|
25
25
|
"Gemfile.lock",
|
26
26
|
"LICENSE",
|
27
|
-
"README.
|
27
|
+
"README.textile",
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION.yml",
|
30
30
|
"bin/java-autotest",
|
31
|
+
"img/java_icon.png",
|
31
32
|
"java-autotest.gemspec",
|
32
33
|
"lib/java_autotest.rb",
|
33
34
|
"lib/java_autotest/autotest.rb",
|
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
|
|
36
37
|
"spec/java_autotest/autotest_spec.rb",
|
37
38
|
"spec/java_autotest/file_spec.rb",
|
38
39
|
"spec/java_autotest/test_runner_spec.rb",
|
40
|
+
"spec/java_autotest_spec.rb",
|
39
41
|
"spec/spec.opts",
|
40
42
|
"spec/spec_helper.rb",
|
41
43
|
"spec/src/main/java/Impl.java",
|
@@ -47,7 +49,8 @@ Gem::Specification.new do |s|
|
|
47
49
|
s.rubygems_version = %q{1.3.7}
|
48
50
|
s.summary = %q{Java AutoTest}
|
49
51
|
s.test_files = [
|
50
|
-
"spec/
|
52
|
+
"spec/java_autotest_spec.rb",
|
53
|
+
"spec/spec_helper.rb",
|
51
54
|
"spec/java_autotest/test_runner_spec.rb",
|
52
55
|
"spec/java_autotest/autotest_spec.rb",
|
53
56
|
"spec/java_autotest/file_spec.rb"
|
data/lib/java_autotest.rb
CHANGED
@@ -3,22 +3,16 @@ require File.dirname(__FILE__) + '/../lib/java_autotest/file'
|
|
3
3
|
require File.dirname(__FILE__) + '/../lib/java_autotest/test_runner'
|
4
4
|
|
5
5
|
module JavaAutoTest
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
class Main
|
7
|
+
def self.execute
|
8
|
+
autotest = AutoTest.new
|
9
|
+
loop do
|
10
|
+
begin
|
11
|
+
sleep until autotest.listen
|
12
|
+
rescue Interrupt
|
13
|
+
break
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
19
18
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
@@ -1,35 +1,37 @@
|
|
1
1
|
class AutoTest
|
2
|
-
|
2
|
+
attr_accessor :run_at, :files, :test_runner
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
4
|
+
def initialize
|
5
|
+
@files = File.find_java_files
|
6
|
+
@test_runner = TestRunner.new
|
7
|
+
@test_runner.run_all_tests
|
8
|
+
@run_at = Time.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def listen
|
12
|
+
@files.each do |file|
|
13
|
+
if (File.atime(file).to_i > @run_at.to_i)
|
14
|
+
run(file)
|
15
|
+
break
|
16
|
+
end
|
17
|
+
end
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(file)
|
22
|
+
test_class = find_test_class file
|
23
|
+
puts "Running test to #{test_class}."
|
24
|
+
green = @test_runner.run_test(test_class)
|
25
|
+
@test_runner.run_all_tests if green
|
26
|
+
reset
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_test_class(file)
|
30
|
+
return file.split("/").last.split(".java").last.concat("Test") unless file.include? "Test.java"
|
31
|
+
file.split("/").last.split(".").first
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset
|
35
|
+
@run_at = Time.new
|
36
|
+
end
|
35
37
|
end
|
@@ -1,9 +1,40 @@
|
|
1
1
|
class TestRunner
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
attr_accessor :build_tool
|
3
|
+
ICON = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'img', 'java_icon.png'))
|
4
|
+
Title = 'Java AutoTest'
|
5
|
+
|
6
|
+
def self.valid_tools
|
7
|
+
%w(mvn gradle)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@build_tool = discover_build_tool
|
12
|
+
end
|
13
|
+
|
14
|
+
def discover_build_tool
|
15
|
+
File.exists?("build.gradle") ? "gradle" : "mvn"
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_test(test_class)
|
19
|
+
command = ".single" if @build_tool == "gradle"
|
20
|
+
green = system("#{@build_tool} -Dtest#{command}=#{test_class} test")
|
21
|
+
notify "Test Failure: #{test_class}" unless green
|
22
|
+
green
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_all_tests
|
26
|
+
green = system("#{@build_tool} test")
|
27
|
+
notify "Build Success" if green
|
28
|
+
notify "Build Broken" unless green
|
29
|
+
end
|
30
|
+
|
31
|
+
def notify(message)
|
32
|
+
case RUBY_PLATFORM
|
33
|
+
when /darwin/
|
34
|
+
system "growlnotify -t '#{Title}' -m '#{message}' --image #{ICON}"
|
35
|
+
when /linux/
|
36
|
+
system "notify-send '#{Title}' '#{message}' --icon #{ICON}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
9
40
|
end
|
@@ -3,44 +3,46 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
3
3
|
describe AutoTest do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
|
7
|
-
|
6
|
+
test_runner = mock(TestRunner)
|
7
|
+
TestRunner.stub!(:new).and_return(test_runner)
|
8
|
+
test_runner.should_receive(:run_all_tests)
|
9
|
+
@autotest = AutoTest.new
|
10
|
+
@class = "src/main/java/app/model/Order.java"
|
8
11
|
end
|
9
|
-
|
10
|
-
context "run test" do
|
11
|
-
|
12
|
+
|
13
|
+
context "run single test" do
|
14
|
+
|
12
15
|
before(:each) do
|
13
|
-
|
16
|
+
@autotest.test_runner.stub!(:run_test).and_return false
|
14
17
|
end
|
15
|
-
|
16
|
-
it "should reset
|
18
|
+
|
19
|
+
it "should reset run_at after run" do
|
17
20
|
now = mock(Time)
|
18
|
-
Time.stub!(:new).and_return
|
19
|
-
|
20
|
-
|
21
|
+
Time.stub!(:new).and_return now
|
22
|
+
@autotest.run(@class)
|
23
|
+
@autotest.run_at.should == now
|
21
24
|
end
|
22
|
-
|
25
|
+
|
23
26
|
it "cannot run all test if test fail" do
|
24
|
-
|
27
|
+
@autotest.test_runner.should_not_receive(:run_all_tests)
|
25
28
|
@autotest.run(@class)
|
26
29
|
end
|
27
|
-
|
30
|
+
|
28
31
|
it "should run all test if test pass" do
|
29
|
-
|
30
|
-
|
32
|
+
@autotest.test_runner.stub!(:run_test).and_return true
|
33
|
+
@autotest.test_runner.should_receive(:run_all_tests)
|
31
34
|
@autotest.run(@class)
|
32
35
|
end
|
33
|
-
|
36
|
+
|
34
37
|
end
|
35
|
-
|
38
|
+
|
36
39
|
it "should find test class name when class is not a test class" do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
test_class = @autotest.find_test_class(@class)
|
41
|
+
test_class.should == "OrderTest"
|
42
|
+
end
|
43
|
+
|
41
44
|
it "should find test class name when class is a test class" do
|
42
45
|
test_class = @autotest.find_test_class("src/test/java/app/model/OrderTest.java")
|
43
|
-
test_class.should == "OrderTest
|
46
|
+
test_class.should == "OrderTest"
|
44
47
|
end
|
45
|
-
|
46
48
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe File do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
context "find java files in source folder" do
|
6
|
+
before(:each) do
|
7
7
|
@files = File.find_java_files("spec/src")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should find impl file" do
|
11
|
-
@files[0].should == "spec/src/main/java/Impl.java"
|
12
8
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
|
10
|
+
it "should find impl file" do
|
11
|
+
@files[0].should == "spec/src/main/java/Impl.java"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should find test file" do
|
15
|
+
@files[1].should == "spec/src/test/java/ImplTest.java"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
19
|
end
|
@@ -1,16 +1,107 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe TestRunner do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
|
5
|
+
context "valid build tools" do
|
6
|
+
it "should support maven" do
|
7
|
+
TestRunner.valid_tools.include?("mvn").should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should support gradle" do
|
11
|
+
TestRunner.valid_tools.include?("gradle").should be_true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "all tests" do
|
16
|
+
before(:all) do
|
17
|
+
@test_runner = TestRunner.new
|
18
|
+
@message = "java autotest is awesome!"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should notify user when build fail" do
|
22
|
+
@test_runner.should_receive(:system).and_return false
|
23
|
+
@test_runner.should_receive(:notify).with("Build Broken")
|
24
|
+
@test_runner.run_all_tests
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should notify user when all build pass" do
|
28
|
+
@test_runner.stub!(:system).and_return true
|
29
|
+
@test_runner.should_receive(:notify).with("Build Success")
|
30
|
+
@test_runner.run_all_tests
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should run all tests to maven" do
|
34
|
+
@test_runner.should_receive(:system).with("mvn test").and_return true
|
35
|
+
@test_runner.stub!(:notify)
|
36
|
+
@test_runner.run_all_tests
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should run all tests to gradle" do
|
40
|
+
File.stub(:exists?).with("build.gradle").and_return true
|
41
|
+
test_runner = TestRunner.new
|
42
|
+
test_runner.stub!(:notify)
|
43
|
+
test_runner.should_receive(:system).with("gradle test").and_return true
|
44
|
+
test_runner.run_all_tests
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "single test" do
|
49
|
+
before(:each) do
|
50
|
+
@test_class = "ImplTest"
|
51
|
+
@test_runner = TestRunner.new
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should notify user when test fail" do
|
55
|
+
@test_runner.should_receive(:system).and_return false
|
56
|
+
@test_runner.should_receive(:notify).with("Test Failure: #{@test_class}")
|
57
|
+
@test_runner.run_test(@test_class).should be_false
|
58
|
+
end
|
59
|
+
|
60
|
+
it "cannot notify user when test pass" do
|
61
|
+
@test_runner.should_receive(:system).and_return true
|
62
|
+
@test_runner.should_not_receive(:notify)
|
63
|
+
@test_runner.run_test(@test_class).should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should run single test to maven" do
|
67
|
+
command = "mvn -Dtest=#{@test_class} test"
|
68
|
+
@test_runner.should_receive(:system).with(command).and_return true
|
69
|
+
@test_runner.run_test(@test_class).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should run gradle single test" do
|
73
|
+
File.stub(:exists?).with("build.gradle").and_return true
|
74
|
+
test_runner = TestRunner.new
|
75
|
+
command = "gradle -Dtest.single=#{@test_class} test"
|
76
|
+
test_runner.should_receive(:system).with(command).and_return true
|
77
|
+
test_runner.run_test(@test_class).should be_true
|
78
|
+
end
|
8
79
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
80
|
+
|
81
|
+
context "notify user" do
|
82
|
+
before(:all) do
|
83
|
+
@test_runner = TestRunner.new
|
84
|
+
@current_platform = RUBY_PLATFORM
|
85
|
+
@message = "java autotest is awesome!"
|
86
|
+
end
|
87
|
+
|
88
|
+
after(:all) do
|
89
|
+
RUBY_PLATFORM = @current_platform
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be able to notify on linux OS" do
|
93
|
+
RUBY_PLATFORM = "linux"
|
94
|
+
command = "notify-send '#{TestRunner::Title}' '#{@message}' --icon #{TestRunner::ICON}"
|
95
|
+
@test_runner.should_receive(:system).with(command)
|
96
|
+
@test_runner.notify(@message)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should be able to notify on Mac OS X" do
|
100
|
+
RUBY_PLATFORM = "darwin"
|
101
|
+
command = "growlnotify -t '#{TestRunner::Title}' -m '#{@message}' --image #{TestRunner::ICON}"
|
102
|
+
@test_runner.should_receive(:system).with(command)
|
103
|
+
@test_runner.notify(@message)
|
104
|
+
end
|
14
105
|
end
|
15
|
-
|
106
|
+
|
16
107
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: java-autotest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- rodolfoliviero
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-30 00:00:00 -03:00
|
19
19
|
default_executable: java-autotest
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -42,17 +42,18 @@ extensions: []
|
|
42
42
|
|
43
43
|
extra_rdoc_files:
|
44
44
|
- LICENSE
|
45
|
-
- README.
|
45
|
+
- README.textile
|
46
46
|
files:
|
47
47
|
- .document
|
48
48
|
- .gitignore
|
49
49
|
- Gemfile
|
50
50
|
- Gemfile.lock
|
51
51
|
- LICENSE
|
52
|
-
- README.
|
52
|
+
- README.textile
|
53
53
|
- Rakefile
|
54
54
|
- VERSION.yml
|
55
55
|
- bin/java-autotest
|
56
|
+
- img/java_icon.png
|
56
57
|
- java-autotest.gemspec
|
57
58
|
- lib/java_autotest.rb
|
58
59
|
- lib/java_autotest/autotest.rb
|
@@ -61,6 +62,7 @@ files:
|
|
61
62
|
- spec/java_autotest/autotest_spec.rb
|
62
63
|
- spec/java_autotest/file_spec.rb
|
63
64
|
- spec/java_autotest/test_runner_spec.rb
|
65
|
+
- spec/java_autotest_spec.rb
|
64
66
|
- spec/spec.opts
|
65
67
|
- spec/spec_helper.rb
|
66
68
|
- spec/src/main/java/Impl.java
|
@@ -100,6 +102,7 @@ signing_key:
|
|
100
102
|
specification_version: 3
|
101
103
|
summary: Java AutoTest
|
102
104
|
test_files:
|
105
|
+
- spec/java_autotest_spec.rb
|
103
106
|
- spec/spec_helper.rb
|
104
107
|
- spec/java_autotest/test_runner_spec.rb
|
105
108
|
- spec/java_autotest/autotest_spec.rb
|