I ended up creating a class, from which my two test classes inherit,
that does the bookkeeping.  I needed to trap the failed assertions
anyway because they caused the test to abort.  Here's what I ended up
with - I would have made it a module to include but I couldn't figure
out how create a class method in the including class
(self.show_subtotals() below).  <classname>.show_subtotals gets called
after each subseries of tests

class Filterbase

    @@tests = 0
    @@passes = 0
    @@failures = 0

    def do_assertion(assert_test, msg)
        begin
            assert(assert_test, msg)
        rescue Test::Unit::AssertionFailedError => e
            puts e.to_s
            puts "BACKTRACE follows"
            puts e.backtrace.reject {|x| x =~ /^c:/}
            puts "\n"
            @@failures = @@failures + 1
        else
            @@passes = @@passes + 1
        ensure
            @@tests = @@tests + 1
#           puts "T:#{@@tests}:P:#{@@passes}:F:#{@@failures}:"
        end
    end

    def self.show_subtotals
        puts "#{@@tests} Assertions, #{@@failures} Failures"
        puts "\n"
    end

end


On or about Mon, 22 Aug 2005 11:22:52 -0500
Bret Pettichord <[EMAIL PROTECTED]> allegedly wrote:

> This is a hard problem, that i'm still looking for a good answer.
> 
> I've spent time investigating it. The problem is that there are two 
> different versions of add_assertion, the method that updates the
> assertion count.
> 
> One of them is in Test::Unit::TestCase -- and it is what you get if
> you do what Warren did below.
> 
> The other is is Test::Unit::Assertions -- and this is the one that
> doesn't actually count your assertions.
> 
> The solution? I don't know. I've been meaning to write up this
> problem on ruby-talk and see if i could get some help there with the
> problem.
> 
> With time i'd like to emulate WET and add methods like ie.text_field
> (:name, 'foo').verify('bar') but this problem needs to get figured
> out first.
> 
> I suggest raising this issue on that forum.
> 
> Bret
> 
> At 10:43 AM 8/22/2005, Warren Pollans wrote:
> >Hello,
> >
> >I have a similar problem/confusion.  My assertions are contained in
> >instance methods of classes defined in an external file - so I don't
> >think the suggestion below is applicable - at least it didn't work
> >when I tried it. The page I'm testing has 4 forms - forms 1 and 4 are
> >nearly identical (aside from form element names) and forms 2 and 3
> >are also similar - so putting the assertions into instance methods
> >seemed the natural thing to do. My test script follows - the results
> >show only one assertion - in test_a.  I'd like to be able to see the
> >total count of assertions.  The tests work fine - I'd just like to
> >see more information - I am imagine I could keep the count myself
> >but suspect that there must be a way to have watir or test/unit do
> >it for me.
> >
> >Any suggestions would be appreciated.  I'm still very new to ruby and
> >watir and windows - I'm porting tests from perl and WWW::Mechanize -
> >Over-explaining accepted :-)
> >
> >Here's my test script:
> >
> >++++++++++++++++++++++++++
> >
> >$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 ==
> >__FILE__
> >
> >require 'unittests/setup'  ##  from watir unittests
> >require 'unittests/filter_settings'  ##  classes defined here
> >
> >$url = url
> >$uid = userid
> >$pas = password
> >
> >class TC_filtersettings < Test::Unit::TestCase
> >
> >         include Watir
> >
> >         def setup()
> >                 $ie.goto($url)
> >         end
> >
> >         def test_a_login
> >                 $ie.text_field(:name, "userid").set($uid)
> >                 $ie.text_field(:name, "password").set($pas)
> >                 $ie.button(:value, "Login").click
> >                 $ie.wait
> >                 assert( $ie.title =~ /Email Defense Solution/, "Got
> > to
> >mailset_spam page" )
> >         end
> >
> >         ##  Spam Settings
> >         def test_b_spam
> >                 Filterbutton.new(1, "spam_handling", 1).button_test
> > () Filterbutton.new(1, "spam_handling", 2).button_test()
> >                 Filterbutton.new(1, "spam_handling", 3).button_test
> > () end
> >
> >         ##  Virus Settings
> >         def test_c_virus
> >                 Filterbutton.new(4, "virus_scanning", 1).button_test
> > () Filterbutton.new(4, "virus_scanning", 2).button_test()
> >         end
> >
> >         def test_d_whitelist
> >                 wl = Filterlist.new('whitelist', 'form1')
> >                 wl.clear_list()
> >                 wl.getAddlist.each {|x| wl.add2list(x[0], x[1])}
> >                 wl.getSearchlist.each {|x| wl.search_list(x[0], x
> > [1])} wl.delete_first()
> >                 wl.clear_list()
> >         end
> >
> >         def test_e_blacklist
> >                 bl = Filterlist.new('blacklist', 'form2')
> >                 bl.clear_list()
> >                 bl.getAddlist.each {|x| bl.add2list(x[0], x[1])}
> >                 bl.getSearchlist.each {|x| bl.search_list(x[0], x
> > [1])} bl.delete_first()
> >                 bl.clear_list()
> >         end
> >end
> >
> >++++++++++++++++++++
> >
> >
> >On or about Fri, 19 Aug 2005 19:11:48 -0500
> >Bret Pettichord <[EMAIL PROTECTED]> allegedly wrote:
> >
> > > I suggest that you put your library methods in a Module. Thus:
> > >
> > > # library.rb
> > > module MyLibrary
> > >    def my_library_method(arg)
> > >          # code...
> > >    end
> > > end
> > >
> > > # tests.rb
> > > require 'test/unit'
> > > require 'library.rb'
> > >
> > > class TC1 << Test::Unit::TestCase
> > >    include MyLibrary
> > >    def test_method
> > >      my_library_method arg
> > >      # more code
> > >    end
> > > end
> > >
> > >
> >_______________________________________________
> >Wtr-general mailing list
> >[email protected]
> >http://rubyforge.org/mailman/listinfo/wtr-general
> 
> _____________________
>   Bret Pettichord
>   www.pettichord.com
> 
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to