Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > what runs when running tests?

Reply
Thread Tools

what runs when running tests?

 
 
kelly
Guest
Posts: n/a
 
      02-14-2007
I guess I'm still learning ruby.

While looking through the test code I realized I don't see what
actually _runs_.

My tests extend Test::Unit::TestCase, and define tests as

def test_sometestname
# some testing stuff
end

I scanned Test::Unit::TestCase and I see a bunch of function
definitions, but I don't see what runs. I guess I'm looking for a
method or piece of code that starts running, initializes things, finds
the test_* test methods and starts running them.

It's probably staring me in the face. Please point it out to me.

Thank you.

-Kelly


 
Reply With Quote
 
 
 
 
Austin Ziegler
Guest
Posts: n/a
 
      02-14-2007
On 2/14/07, kelly <> wrote:
> I guess I'm still learning ruby.
>
> While looking through the test code I realized I don't see what
> actually _runs_.


A TestRunner.

See the files in lib/1.8/test/unit for more information if you want to
understand Test::Unit.

-austin
--
Austin Ziegler * * http://www.halostatue.ca/
* * http://www.halostatue.ca/feed/
*

 
Reply With Quote
 
 
 
 
Lyle Johnson
Guest
Posts: n/a
 
      02-14-2007
On 2/14/07, kelly <> wrote:

> I scanned Test::Unit::TestCase and I see a bunch of function
> definitions, but I don't see what runs. I guess I'm looking for a
> method or piece of code that starts running, initializes things, finds
> the test_* test methods and starts running them.


To expand on Austin's answer just a little: I think the magic that
you're looking for is at the tail end of unit.rb, in the
lib/1.8/test/unit directory of the standard library. Test::Unit takes
advantage of the at_exit() method to register a little bit of code
that invokes the Test::Unit AutoRunner class right before the
interpreter exits.

 
Reply With Quote
 
kelly
Guest
Posts: n/a
 
      02-14-2007
Thanks.

Here is what I've learned so far:

I'm testing rails code. The generated rails test stubs have this line:

require File.dirname(__FILE__) + '/../test_helper'

app/test/test_helper.rb contains this line:

require 'test_help'

lib/ruby/gems/1.8/rails-1.1.6/lib/test_help.rb contains this line:

require 'test/unit'

lib/ruby/1.8/test/unit.rb contains these lines:

at_exit do
unless $! || Test::Unit.run?
exit Test::Unit::AutoRunner.run
end
end

I think this is the magic that runs the tests.

-Kelly


On Feb 14, 8:46 am, "Austin Ziegler" <halosta...@gmail.com> wrote:
> On 2/14/07, kelly <railsina...@gmail.com> wrote:
>
> > I guess I'm still learning ruby.

>
> > While looking through the test code I realized I don't see what
> > actually _runs_.

>
> A TestRunner.
>
> See the files in lib/1.8/test/unit for more information if you want to
> understand Test::Unit.
>
> -austin
> --
> Austin Ziegler * halosta...@gmail.com *http://www.halostatue.ca/
> * aus...@halostatue.ca *http://www.halostatue.ca/feed/
> * aus...@zieglers.ca



 
Reply With Quote
 
kelly
Guest
Posts: n/a
 
      02-14-2007
Lyle,

Thanks very much.

I see the code you refer to. Now I wonder why it is done using the
at_exit method -- seems a little obtuse to me.

My original question has been answered. Thanks again.

-Kelly


On Feb 14, 9:22 am, "Lyle Johnson" <lyle.john...@gmail.com> wrote:
> On 2/14/07, kelly <railsina...@gmail.com> wrote:
>
> > I scanned Test::Unit::TestCase and I see a bunch of function
> > definitions, but I don't see what runs. I guess I'm looking for a
> > method or piece of code that starts running, initializes things, finds
> > the test_* test methods and starts running them.

>
> To expand on Austin's answer just a little: I think the magic that
> you're looking for is at the tail end of unit.rb, in the
> lib/1.8/test/unit directory of the standard library. Test::Unit takes
> advantage of the at_exit() method to register a little bit of code
> that invokes the Test::Unit AutoRunner class right before the
> interpreter exits.



 
Reply With Quote
 
Bret Pettichord
Guest
Posts: n/a
 
      02-14-2007
On Feb 14, 11:41 am, "kelly" <railsina...@gmail.com> wrote:
> I see the code you refer to. Now I wonder why it is done using the
> at_exit method -- seems a little obtuse to me.


In Python's unit testing framework, you have to explicitly include
this code in every one of your test files. It's a real pain. Using the
at_exit hook in Ruby makes your unit tests cleaner.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A router running under WinXP runs under Windows Vista too? Peter Wagner Wireless Networking 12 02-04-2008 11:02 PM
Ruby pro0gram runs on two machines and is not running on third manolmm@gmail.com Ruby 0 01-21-2008 02:00 PM
problem in code running on msvs2008 c++ while same logic runs fine onturbo c++ 3.0 ashjas C++ 7 12-10-2007 03:40 PM
help : my jar file is not running under linux terminal , but it runs under JbuilderX ide bronby Java 1 07-15-2005 07:23 AM
500 error running asp on a virtual directory that runs asp.net with no errors Rocio ASP General 1 06-07-2004 11:06 PM



Advertisments