semilla 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +56 -0
- data/lib/semilla/flash_player.rb +21 -0
- data/lib/semilla/platform.rb +15 -0
- data/lib/semilla/report_server.rb +152 -152
- data/lib/semilla/reports.rb +202 -202
- data/lib/semilla/test.rb +93 -95
- data/lib/semilla/test_runner.rb +87 -87
- data/lib/semilla/version.rb +3 -3
- data/lib/semilla.rb +38 -36
- data/rakefile.rb +38 -38
- data/semilla.gemspec +45 -45
- metadata +9 -7
- data/README.textile +0 -58
data/lib/semilla/reports.rb
CHANGED
@@ -1,203 +1,203 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
require 'rexml/formatters/default'
|
3
|
-
require 'socket'
|
4
|
-
require 'time'
|
5
|
-
|
6
|
-
|
7
|
-
module Semilla
|
8
|
-
|
9
|
-
#Define a test case
|
10
|
-
class FlexUnitTestCase
|
11
|
-
|
12
|
-
attr_accessor :classname, :name, :time, :status, :msg
|
13
|
-
|
14
|
-
|
15
|
-
def initWith(xml)
|
16
|
-
#parse tag
|
17
|
-
if xml.is_a? String
|
18
|
-
doc = REXML::Document.new xml
|
19
|
-
else
|
20
|
-
doc = REXML::Document.new
|
21
|
-
doc.add_element xml
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
@classname = doc.root.attribute("classname").value.sub "::", "." #Change the :: to .
|
26
|
-
@name = doc.root.attribute("name").value #method name
|
27
|
-
@time = doc.root.attribute("time").value.to_i / 1000.0 #time to milliseconds
|
28
|
-
@status = doc.root.attribute("status").value #status
|
29
|
-
@msg = doc.root.elements[1] if doc.root.elements.count > 0
|
30
|
-
|
31
|
-
|
32
|
-
#If time is reported as 0 by flex unit, set to 1 millisecond
|
33
|
-
#@time = 1/1000.0 if @time == 0
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def toXml
|
38
|
-
element = REXML::Element.new "testcase"
|
39
|
-
element.add_attribute "classname", @classname
|
40
|
-
element.add_attribute "name", @name
|
41
|
-
element.add_attribute "time", @time
|
42
|
-
element.add_attribute "status", @status
|
43
|
-
element.add_element @msg unless @msg.nil?
|
44
|
-
|
45
|
-
return element
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
#Defin a test suite
|
50
|
-
class FlexUnitTestSuite
|
51
|
-
|
52
|
-
def initialize
|
53
|
-
@testCases = Array.new
|
54
|
-
@classname = ""
|
55
|
-
@totalTime = 0.0
|
56
|
-
@id = 0
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
attr_reader :totalTime, :classname
|
61
|
-
attr_accessor :id
|
62
|
-
|
63
|
-
|
64
|
-
def addCase(tc)
|
65
|
-
if tc.is_a? FlexUnitTestCase
|
66
|
-
@classname = tc.classname
|
67
|
-
@testCases << tc
|
68
|
-
@totalTime = @totalTime + tc.time
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def testCount
|
74
|
-
@testCases.count
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
def name
|
79
|
-
return @classname[/[^\.]*$/] #Get the text at the end of the line after the last dot
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
def package
|
84
|
-
if @classname.include? "."
|
85
|
-
@classname[/(?<package>.*)([\.])/, "package"]
|
86
|
-
#using named captures check: "?<package>"
|
87
|
-
else
|
88
|
-
""
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
def failures
|
94
|
-
return @testCases.count { |tc| tc.status == "failure" }
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def errors
|
99
|
-
return @testCases.count { |tc| tc.status == "error" }
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
def ignores
|
104
|
-
return @testCases.count { |tc| tc.status == "ignore" }
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
def toXml
|
109
|
-
element = REXML::Element.new "testsuite"
|
110
|
-
element.add_attribute "hostname", Socket.gethostname
|
111
|
-
element.add_attribute "id", self.id
|
112
|
-
#element.add_attribute "package", self.package
|
113
|
-
element.add_attribute "name", self.classname
|
114
|
-
element.add_attribute "tests", self.testCount
|
115
|
-
element.add_attribute "failures", self.failures
|
116
|
-
element.add_attribute "errors", self.errors
|
117
|
-
element.add_attribute "skipped", self.ignores
|
118
|
-
element.add_attribute "time", self.totalTime
|
119
|
-
element.add_attribute "timestamp", Time.now.utc.iso8601
|
120
|
-
|
121
|
-
@testCases.each do |tc|
|
122
|
-
element.add_element tc.toXml
|
123
|
-
end
|
124
|
-
|
125
|
-
return element
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
def self.writePrettyXml(element, filename)
|
132
|
-
#create anew xml document
|
133
|
-
outdoc = REXML::Document.new
|
134
|
-
|
135
|
-
#Create the xml declaration
|
136
|
-
xmldeclaration = REXML::XMLDecl.new
|
137
|
-
xmldeclaration.dowrite
|
138
|
-
xmldeclaration.encoding = "UTF-8"
|
139
|
-
outdoc << xmldeclaration
|
140
|
-
|
141
|
-
#Add the element
|
142
|
-
outdoc << element
|
143
|
-
|
144
|
-
#Write to a file
|
145
|
-
f = File.new filename, "w"
|
146
|
-
formatter = REXML::Formatters::Pretty.new
|
147
|
-
formatter.write(outdoc, f)
|
148
|
-
f.close
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
#converts an xml report from flash, into an array of FlexUnitTestSuite
|
153
|
-
def self.processReports(xmlresults)
|
154
|
-
|
155
|
-
testResults = REXML::Document.new xmlresults
|
156
|
-
|
157
|
-
suites = Hash.new
|
158
|
-
|
159
|
-
testResults.elements.each "report/testcase" do |element|
|
160
|
-
|
161
|
-
#Create the testcase
|
162
|
-
tc = FlexUnitTestCase.new
|
163
|
-
tc.initWith element
|
164
|
-
|
165
|
-
#Check if we dont have a suite for the classname
|
166
|
-
unless suites.has_key? tc.classname
|
167
|
-
#make a new suite
|
168
|
-
s = FlexUnitTestSuite.new
|
169
|
-
suites[tc.classname] = s
|
170
|
-
end
|
171
|
-
|
172
|
-
suite = suites[tc.classname]
|
173
|
-
suite.addCase tc
|
174
|
-
puts " [TestCase] #{tc.classname} => #{tc.name}, #{tc.status}"
|
175
|
-
end
|
176
|
-
|
177
|
-
return suites
|
178
|
-
end
|
179
|
-
|
180
|
-
|
181
|
-
#writes junit xml files for each item in the suites hash
|
182
|
-
def self.createReports(suites, outfolder = "test-report")
|
183
|
-
|
184
|
-
testcount = 0
|
185
|
-
testfails = 0
|
186
|
-
testerr = 0
|
187
|
-
testignores = 0
|
188
|
-
suites.each do |name, suite|
|
189
|
-
#write individual report file
|
190
|
-
writePrettyXml suite.toXml, "#{outfolder}/TEST-#{suite.classname}.xml"
|
191
|
-
testcount += suite.testCount
|
192
|
-
testfails += suite.failures
|
193
|
-
testerr += suite.errors
|
194
|
-
testignores += suite.ignores
|
195
|
-
end
|
196
|
-
|
197
|
-
testPassed = testcount - testfails - testerr - testignores
|
198
|
-
testok = testPassed.to_f / testcount.to_f * 100.0
|
199
|
-
puts "Success [#{testPassed}/#{testcount}] #{sprintf('%.1f', testok)}%, Fails [#{testfails}], Errors [#{testerr}], Ignored [#{testignores}]"
|
200
|
-
return testfails + testerr
|
201
|
-
end
|
202
|
-
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'rexml/formatters/default'
|
3
|
+
require 'socket'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
|
7
|
+
module Semilla
|
8
|
+
|
9
|
+
#Define a test case
|
10
|
+
class FlexUnitTestCase
|
11
|
+
|
12
|
+
attr_accessor :classname, :name, :time, :status, :msg
|
13
|
+
|
14
|
+
|
15
|
+
def initWith(xml)
|
16
|
+
#parse tag
|
17
|
+
if xml.is_a? String
|
18
|
+
doc = REXML::Document.new xml
|
19
|
+
else
|
20
|
+
doc = REXML::Document.new
|
21
|
+
doc.add_element xml
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
@classname = doc.root.attribute("classname").value.sub "::", "." #Change the :: to .
|
26
|
+
@name = doc.root.attribute("name").value #method name
|
27
|
+
@time = doc.root.attribute("time").value.to_i / 1000.0 #time to milliseconds
|
28
|
+
@status = doc.root.attribute("status").value #status
|
29
|
+
@msg = doc.root.elements[1] if doc.root.elements.count > 0
|
30
|
+
|
31
|
+
|
32
|
+
#If time is reported as 0 by flex unit, set to 1 millisecond
|
33
|
+
#@time = 1/1000.0 if @time == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def toXml
|
38
|
+
element = REXML::Element.new "testcase"
|
39
|
+
element.add_attribute "classname", @classname
|
40
|
+
element.add_attribute "name", @name
|
41
|
+
element.add_attribute "time", @time
|
42
|
+
element.add_attribute "status", @status
|
43
|
+
element.add_element @msg unless @msg.nil?
|
44
|
+
|
45
|
+
return element
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#Defin a test suite
|
50
|
+
class FlexUnitTestSuite
|
51
|
+
|
52
|
+
def initialize
|
53
|
+
@testCases = Array.new
|
54
|
+
@classname = ""
|
55
|
+
@totalTime = 0.0
|
56
|
+
@id = 0
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
attr_reader :totalTime, :classname
|
61
|
+
attr_accessor :id
|
62
|
+
|
63
|
+
|
64
|
+
def addCase(tc)
|
65
|
+
if tc.is_a? FlexUnitTestCase
|
66
|
+
@classname = tc.classname
|
67
|
+
@testCases << tc
|
68
|
+
@totalTime = @totalTime + tc.time
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def testCount
|
74
|
+
@testCases.count
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def name
|
79
|
+
return @classname[/[^\.]*$/] #Get the text at the end of the line after the last dot
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def package
|
84
|
+
if @classname.include? "."
|
85
|
+
@classname[/(?<package>.*)([\.])/, "package"]
|
86
|
+
#using named captures check: "?<package>"
|
87
|
+
else
|
88
|
+
""
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def failures
|
94
|
+
return @testCases.count { |tc| tc.status == "failure" }
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def errors
|
99
|
+
return @testCases.count { |tc| tc.status == "error" }
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def ignores
|
104
|
+
return @testCases.count { |tc| tc.status == "ignore" }
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def toXml
|
109
|
+
element = REXML::Element.new "testsuite"
|
110
|
+
element.add_attribute "hostname", Socket.gethostname
|
111
|
+
element.add_attribute "id", self.id
|
112
|
+
#element.add_attribute "package", self.package
|
113
|
+
element.add_attribute "name", self.classname
|
114
|
+
element.add_attribute "tests", self.testCount
|
115
|
+
element.add_attribute "failures", self.failures
|
116
|
+
element.add_attribute "errors", self.errors
|
117
|
+
element.add_attribute "skipped", self.ignores
|
118
|
+
element.add_attribute "time", self.totalTime
|
119
|
+
element.add_attribute "timestamp", Time.now.utc.iso8601
|
120
|
+
|
121
|
+
@testCases.each do |tc|
|
122
|
+
element.add_element tc.toXml
|
123
|
+
end
|
124
|
+
|
125
|
+
return element
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def self.writePrettyXml(element, filename)
|
132
|
+
#create anew xml document
|
133
|
+
outdoc = REXML::Document.new
|
134
|
+
|
135
|
+
#Create the xml declaration
|
136
|
+
xmldeclaration = REXML::XMLDecl.new
|
137
|
+
xmldeclaration.dowrite
|
138
|
+
xmldeclaration.encoding = "UTF-8"
|
139
|
+
outdoc << xmldeclaration
|
140
|
+
|
141
|
+
#Add the element
|
142
|
+
outdoc << element
|
143
|
+
|
144
|
+
#Write to a file
|
145
|
+
f = File.new filename, "w"
|
146
|
+
formatter = REXML::Formatters::Pretty.new
|
147
|
+
formatter.write(outdoc, f)
|
148
|
+
f.close
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
#converts an xml report from flash, into an array of FlexUnitTestSuite
|
153
|
+
def self.processReports(xmlresults)
|
154
|
+
|
155
|
+
testResults = REXML::Document.new xmlresults
|
156
|
+
|
157
|
+
suites = Hash.new
|
158
|
+
|
159
|
+
testResults.elements.each "report/testcase" do |element|
|
160
|
+
|
161
|
+
#Create the testcase
|
162
|
+
tc = FlexUnitTestCase.new
|
163
|
+
tc.initWith element
|
164
|
+
|
165
|
+
#Check if we dont have a suite for the classname
|
166
|
+
unless suites.has_key? tc.classname
|
167
|
+
#make a new suite
|
168
|
+
s = FlexUnitTestSuite.new
|
169
|
+
suites[tc.classname] = s
|
170
|
+
end
|
171
|
+
|
172
|
+
suite = suites[tc.classname]
|
173
|
+
suite.addCase tc
|
174
|
+
puts " [TestCase] #{tc.classname} => #{tc.name}, #{tc.status}"
|
175
|
+
end
|
176
|
+
|
177
|
+
return suites
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
#writes junit xml files for each item in the suites hash
|
182
|
+
def self.createReports(suites, outfolder = "test-report")
|
183
|
+
|
184
|
+
testcount = 0
|
185
|
+
testfails = 0
|
186
|
+
testerr = 0
|
187
|
+
testignores = 0
|
188
|
+
suites.each do |name, suite|
|
189
|
+
#write individual report file
|
190
|
+
writePrettyXml suite.toXml, "#{outfolder}/TEST-#{suite.classname}.xml"
|
191
|
+
testcount += suite.testCount
|
192
|
+
testfails += suite.failures
|
193
|
+
testerr += suite.errors
|
194
|
+
testignores += suite.ignores
|
195
|
+
end
|
196
|
+
|
197
|
+
testPassed = testcount - testfails - testerr - testignores
|
198
|
+
testok = testPassed.to_f / testcount.to_f * 100.0
|
199
|
+
puts "Success [#{testPassed}/#{testcount}] #{sprintf('%.1f', testok)}%, Fails [#{testfails}], Errors [#{testerr}], Ignored [#{testignores}]"
|
200
|
+
return testfails + testerr
|
201
|
+
end
|
202
|
+
|
203
203
|
end
|
data/lib/semilla/test.rb
CHANGED
@@ -1,95 +1,93 @@
|
|
1
|
-
|
2
|
-
require "rexml/document"
|
3
|
-
require "rake"
|
4
|
-
require 'timeout'
|
5
|
-
require 'flashplayer/trust'
|
6
|
-
|
7
|
-
require_relative "reports"
|
8
|
-
require_relative "report_server"
|
9
|
-
|
10
|
-
|
11
|
-
module Semilla
|
12
|
-
class FlexUnitTestTask < Rake::Task
|
13
|
-
|
14
|
-
attr_accessor :serverPort, :player, :swf, :reportpath, :timeout
|
15
|
-
|
16
|
-
|
17
|
-
def initialize(task_name, app)
|
18
|
-
super task_name, app
|
19
|
-
|
20
|
-
@serverPort = 1024
|
21
|
-
@player = ENV['FLASH_PLAYER']
|
22
|
-
@reportpath = "test-report"
|
23
|
-
@timeout = 10 #seconds
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def execute(arg = nil)
|
28
|
-
super arg
|
29
|
-
|
30
|
-
##Check the parameters
|
31
|
-
if @serverPort.nil?
|
32
|
-
fail "Server port not specified."
|
33
|
-
end
|
34
|
-
|
35
|
-
if @swf.nil?
|
36
|
-
fail "No swf path specified."
|
37
|
-
end
|
38
|
-
|
39
|
-
if @reportpath.nil?
|
40
|
-
fail "No report path specified."
|
41
|
-
end
|
42
|
-
|
43
|
-
#Writeout the FlashPlayerTrust file
|
44
|
-
trust = FlashPlayer::Trust.new
|
45
|
-
trust.add File.dirname(@swf)
|
46
|
-
|
47
|
-
puts "[TEST] Start"
|
48
|
-
server = FlexUnitReportServer.new @serverPort
|
49
|
-
serverThread = Thread.new {
|
50
|
-
#Start the server for getting the flex unit results
|
51
|
-
server.start @timeout
|
52
|
-
}
|
53
|
-
sleep 0.5
|
54
|
-
|
55
|
-
#launch flash
|
56
|
-
clientThread = Thread.new {
|
57
|
-
|
58
|
-
begin
|
59
|
-
status = Timeout::timeout @timeout do
|
60
|
-
flashbin = ENV['FLASH_PLAYER']
|
61
|
-
#Run the flash player
|
62
|
-
puts "Running flash..."
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
1
|
+
|
2
|
+
require "rexml/document"
|
3
|
+
require "rake"
|
4
|
+
require 'timeout'
|
5
|
+
require 'flashplayer/trust'
|
6
|
+
|
7
|
+
require_relative "reports"
|
8
|
+
require_relative "report_server"
|
9
|
+
|
10
|
+
|
11
|
+
module Semilla
|
12
|
+
class FlexUnitTestTask < Rake::Task
|
13
|
+
|
14
|
+
attr_accessor :serverPort, :player, :swf, :reportpath, :timeout
|
15
|
+
|
16
|
+
|
17
|
+
def initialize(task_name, app)
|
18
|
+
super task_name, app
|
19
|
+
|
20
|
+
@serverPort = 1024
|
21
|
+
@player = ENV['FLASH_PLAYER']
|
22
|
+
@reportpath = "test-report"
|
23
|
+
@timeout = 10 #seconds
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def execute(arg = nil)
|
28
|
+
super arg
|
29
|
+
|
30
|
+
##Check the parameters
|
31
|
+
if @serverPort.nil?
|
32
|
+
fail "Server port not specified."
|
33
|
+
end
|
34
|
+
|
35
|
+
if @swf.nil?
|
36
|
+
fail "No swf path specified."
|
37
|
+
end
|
38
|
+
|
39
|
+
if @reportpath.nil?
|
40
|
+
fail "No report path specified."
|
41
|
+
end
|
42
|
+
|
43
|
+
#Writeout the FlashPlayerTrust file
|
44
|
+
trust = FlashPlayer::Trust.new
|
45
|
+
trust.add File.dirname(@swf)
|
46
|
+
|
47
|
+
puts "[TEST] Start"
|
48
|
+
server = FlexUnitReportServer.new @serverPort
|
49
|
+
serverThread = Thread.new {
|
50
|
+
#Start the server for getting the flex unit results
|
51
|
+
server.start @timeout
|
52
|
+
}
|
53
|
+
sleep 0.5
|
54
|
+
|
55
|
+
#launch flash
|
56
|
+
clientThread = Thread.new {
|
57
|
+
|
58
|
+
begin
|
59
|
+
status = Timeout::timeout @timeout do
|
60
|
+
flashbin = ENV['FLASH_PLAYER']
|
61
|
+
#Run the flash player
|
62
|
+
puts "Running flash..."
|
63
|
+
fr = Semilla::run_player(flashbin, swf)
|
64
|
+
end
|
65
|
+
rescue Timeout::Error
|
66
|
+
fail "Flash player timeout!!!"
|
67
|
+
end
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
#Wait until finished
|
72
|
+
serverThread.join
|
73
|
+
clientThread.join
|
74
|
+
|
75
|
+
#parse the reports
|
76
|
+
suites = Semilla::processReports server.results
|
77
|
+
#generate junit report
|
78
|
+
failcount = Semilla::createReports suites, @reportpath
|
79
|
+
puts "[TEST] Done"
|
80
|
+
|
81
|
+
fail "Unit tests failed." if failcount > 0
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def self.flex_unit(*args, &body)
|
89
|
+
FlexUnitTestTask.define_task(*args, &body)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
end
|