Hi Marlon,
Have modified the ci_reporter to include passed/failed/error in
ci_reporter.
Also have modified the code to create one xml file instead of multiple
files when you try to run testcases present in different classes.
Modify the TestSuite and TestCase present in Ci_reporter --
(ci_reporter\lib\ci\reporter\test_suite.rb)
# Basic structure representing the running of a test suite. Used to
time tests and store results.
class TestSuite < Struct.new
(:name, :tests, :time, :failures, :errors, :assertions, :passed)
attr_accessor :testcases
attr_accessor :stdout, :stderr
def initialize(name)
super(name.to_s) # RSpec passes a "description" object instead
of a string
@testcases = []
end
# Starts timing the test suite.
def start
@start = Time.now
unless ENV['CI_CAPTURE'] == "off"
@capture_out = OutputCapture.new($stdout) {|io| $stdout =
io }
@capture_err = OutputCapture.new($stderr) {|io| $stderr =
io }
end
end
# Finishes timing the test suite.
def finish
self.tests = testcases.size
self.time = Time.now - @start
#self.failures = testcases.inject(0) {|sum,tc| sum +=
tc.failures.select{|f| f.failure? }.size }
self.failures = 0
testcases.each { |tc|
self.failures += 1 if tc.failure?
}
self.errors = testcases.inject(0) {|sum,tc| sum +=
tc.failures.select{|f| f.error? }.size }
####
self.passed =0
testcases.each { |tc|
self.passed += 1 if !(tc.failure? || tc.error?)
}
#puts "PASSED WAS - #{self.passed}"
####
self.stdout = @capture_out.finish if @capture_out
self.stderr = @capture_err.finish if @capture_err
end
# Creates the xml builder instance used to create the report xml
document.
def create_builder
require 'rubygems'
gem 'builder'
require 'builder'
# :escape_attrs is obsolete in a newer version, but should do
no harm
Builder::XmlMarkup.new(:indent => 2, :escape_attrs => true)
end
# Creates an xml string containing the test suite results.
def to_xml
builder = create_builder
# more recent version of Builder doesn't need the escaping
def builder.trunc!(txt)
txt.sub(/\n.*/m, '...')
end
#builder.instruct!
attrs = {}
each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless
v.nil? || v.to_s.empty? }
builder.testsuite(attrs) do
@testcases.each do |tc|
tc.to_xml(builder)
end
builder.tag! "system-out" do
builder.cdata! self.stdout
end
builder.tag! "system-err" do
builder.cdata! self.stderr
end
end
end
end
class TestCase < Struct.new(:name, :time, :assertions)
attr_accessor :failures
def initialize(*args)
super
@failures = []
end
# Starts timing the test.
def start
@start = Time.now
end
# Finishes timing the test.
def finish
#self.time = Time.now - @start
self.time = (Time.now - @start).to_i # roundoff the time to an
integer
end
# Returns non-nil if the test failed.
def failure?
!failures.empty? && failures.detect {|f| f.failure? }
end
# Returns non-nil if the test had an error.
def error?
!failures.empty? && failures.detect {|f| f.error? }
end
# Writes xml representing the test result to the provided
builder.
def to_xml(builder)
attrs = {}
each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless
v.nil? || v.to_s.empty?}
builder.testcase(attrs) do
failures.each do |failure|
# - This is where the type of failure is checked .. error
or failure
if failure.kind_of?(YNOT::YNOTE::TestUnitFailure)
builder.failure(:type => builder.trunc!
(failure.name), :message => builder.trunc!(failure.message)) do
builder.text!(failure.message + " (#{failure.name})
\n")
builder.text!(failure.location)
end
else
builder.error(:type => builder.trunc!
(failure.name), :message => builder.trunc!(failure.message)) do
builder.text!(failure.message + " (#{failure.name})
\n")
builder.text!(failure.location)
end
end
end
end
end
end
Hope this helps ...
Thanks,
Paul
On Jul 15, 4:28 pm, Marlon <[email protected]> wrote:
> Hi, anybody here knows how to customize xml report generated by
> ci_reports addon. I would like to add more attributes. Example, I want
> to add <testsuite result> PASS/FAIL </testsuite result>.
>
> In addition to this I'm planning to create some kind of a dashboard in
> html form where i can select/check the testcase I want to run.
>
> thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines:
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---