Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- track test/unit assertions

git-svn-id: http://svn.caldersphere.net/svn/main/rubyforge/ci_reporter/trunk@72 b03c2d0b-2f10-0410-a2f9-fc8001506dfa
  • Loading branch information...
commit bae3091d1ccb9568af758a9a6c29cfb4cdc0d656 1 parent cbe1c35
@nicksieger nicksieger authored
View
4 History.txt
@@ -1,3 +1,7 @@
+== 1.1
+
+- Add +assertions+ attribute to the +testsuite+ element that will contain per-suite assertion counts when used with Test::Unit.
+
== 1.0
Initial Release.
View
2  Rakefile
@@ -4,7 +4,7 @@ require 'hoe'
MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "Rakefile",
"lib/**/*.rb", "spec/**/*.rb", "tasks/**/*.rake"]
-Hoe.new("ci_reporter", "1.0") do |p|
+Hoe.new("ci_reporter", "1.1") do |p|
p.rubyforge_name = "caldersphere"
p.url = "http://caldersphere.rubyforge.org/ci_reporter"
p.author = "Nick Sieger"
View
4 lib/ci/reporter/test_suite.rb
@@ -1,7 +1,7 @@
module CI
module Reporter
# 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)
+ class TestSuite < Struct.new(:name, :tests, :time, :failures, :errors, :assertions)
attr_accessor :testcases
def initialize(name)
super
@@ -53,7 +53,7 @@ def builder.trunc!(txt)
end
builder.instruct!
attrs = {}
- each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) }
+ 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)
View
4 lib/ci/reporter/test_unit.rb
@@ -49,6 +49,8 @@ def initialize(suite, report_mgr = nil)
end
def started(result)
+ @suite_result = result
+ @last_assertion_count = 0
@current_suite = nil
@unknown_count = 0
end
@@ -93,6 +95,8 @@ def start_suite(suite_name)
def finish_suite
if @current_suite
@current_suite.finish
+ @current_suite.assertions = @suite_result.assertion_count - @last_assertion_count
+ @last_assertion_count = @suite_result.assertion_count
@report_manager.write_report(@current_suite)
end
end
View
7 spec/ci/reporter/test_suite_spec.rb
@@ -45,6 +45,7 @@
context "TestSuite xml" do
setup do
@suite = CI::Reporter::TestSuite.new("example suite")
+ @suite.assertions = 11
begin
raise StandardError, "an exception occurred"
rescue => e
@@ -77,11 +78,13 @@
xml = @suite.to_xml
doc = REXML::Document.new(xml)
- testsuite = doc.root.elements.to_a('/testsuite')
+ testsuite = doc.root.elements.to_a("/testsuite")
testsuite.length.should == 1
testsuite = testsuite.first
+ testsuite.attributes["name"].should == "example suite"
+ testsuite.attributes["assertions"].should == "11"
- testcases = testsuite.elements.to_a('testcase')
+ testcases = testsuite.elements.to_a("testcase")
testcases.length.should == 3
end
View
20 spec/ci/reporter/test_unit_spec.rb
@@ -4,13 +4,15 @@
setup do
@report_mgr = mock("report manager")
@testunit = CI::Reporter::TestUnit.new(nil, @report_mgr)
+ @result = mock("result")
+ @result.stub!(:assertion_count).and_return(7)
end
specify "should build suites based on adjacent tests with the same class name" do
@suite = nil
@report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
- @testunit.started(mock("result"))
+ @testunit.started(@result)
@testunit.test_started("test_one(TestCaseClass)")
@testunit.test_finished("test_one(TestCaseClass)")
@testunit.test_started("test_two(TestCaseClass)")
@@ -31,7 +33,7 @@
@suites = []
@report_mgr.should_receive(:write_report).twice.and_return {|suite| @suites << suite }
- @testunit.started(mock("result"))
+ @testunit.started(@result)
@testunit.test_started("test_one(TestCaseClass)")
@testunit.test_finished("test_one(TestCaseClass)")
@testunit.test_started("test_two(AnotherTestCaseClass)")
@@ -46,6 +48,18 @@
@suites.last.testcases.first.name.should == "test_two"
end
+ specify "should record assertion counts during test run" do
+ @suite = nil
+ @report_mgr.should_receive(:write_report).and_return {|suite| @suite = suite }
+
+ @testunit.started(@result)
+ @testunit.test_started("test_one(TestCaseClass)")
+ @testunit.test_finished("test_one(TestCaseClass)")
+ @testunit.finished(10)
+
+ @suite.assertions.should == 7
+ end
+
specify "should add failures to testcases when encountering a fault" do
begin
raise StandardError, "error"
@@ -56,7 +70,7 @@
@suite = nil
@report_mgr.should_receive(:write_report).once.and_return {|suite| @suite = suite }
- @testunit.started(mock("result"))
+ @testunit.started(@result)
@testunit.test_started("test_one(TestCaseClass)")
@testunit.test_finished("test_one(TestCaseClass)")
@testunit.test_started("test_two(TestCaseClass)")
Please sign in to comment.
Something went wrong with that request. Please try again.