keyongtech


  keyongtech > ruby

 #1  
02-16-08, 07:35 PM
Peter Recore
Why can't I run a Test::Unit::TestCase from IRB and have it run before I
quit?
I have found this problem mentioned by others. For an example, see this
tutorial about testing:

http://www.nullislove.com/2007/11/14...sting-in-ruby/

>irb --simple-prompt
>> require 'test/unit'

=> true
>> class FirstTests < Test::Unit::TestCase
>> def test_addition
>> assert(1 + 1 == 2)
>> end
>>
>> def test_subtraction
>> assert(1 - 1 == 2)
>> end
>> end

=> nil
>> quit

Loaded suite irb
Started
F
Finished in 0.00119 seconds.

The author mentions that a quirk of irb makes this happen but doesn't
say what the quirk is:

"When we finished the definition, nothing happened. When we exited IRB,
then our tests ran. That’s a characteristic of using IRB for our tests
and won’t be significant as we move on."

Thanks for any insight you have.
 #2  
02-16-08, 09:18 PM
Phlip
Peter Recore wrote:

> "When we finished the definition, nothing happened. When we exited IRB,
> then our tests ran. That’s a characteristic of using IRB for our tests
> and won’t be significant as we move on."


In general, the package has this problem because the best way to run
tests is with an editor. After a change you hit one button, and this runs
the current test. If you don't have editor keystroke bindings there, get
with ZenTest's autotest, and use it to trigger a test run each time you
save your files.

The tests run when IRB exits because RubyUnit is designed to run tests
automatically if you invoke their files with 'ruby file_test.rb'. You
wouldn't need to add these lines to the bottom of each test case:

runner = Test::Unit::UI::Console::TestRunner
got = runner.run(aTestCase.suite)
badThings += got.error_count + got.failure_count

That might work in IRB, too.
 #3  
02-16-08, 10:45 PM
Christopher Dicely
On Feb 16, 2008 11:35 AM, Peter Recore <peterrecore> wrote:
> Why can't I run a Test::Unit::TestCase from IRB and have it run before I
> quit?


You can, you just have to explicitly tell it to run. Normally, you
don't explicitly run Test::Unit tests, you simply define them and then
they run automagically when ruby exits, because the Test::Unit
library, when it is loaded, loads an at_exit routine that will (unless
something has told it not too) run the tests that have been defined.
Its not really an IRB quirk that stops them from running until you
exit, its just that when you run a script with unit tests
"standalone", you don't realize that the tests are run when it is
exiting. With IRB, you just notice what is going on regularly when you
use Test::Unit.

The RDoc for Test::Unit gives this example of how to explicitly run a test case:

require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TC_MyTest)
Similar Threads
Thread Thread Starter
Running Unit Test Remotely

Hi, Some of my future unit / component test may run op to several hours. I would like to run them simultaneously and on a different machine. Arguably, I misuse the unit...

Martijn Kaag
Restoring state of database after running a Unit test

Sorry if this is a newbie question. My application sends data (via TCP/IP sockets) to a 3rd party application which dispenses the data to various tables in a SQL Server 2005...

sprash
fivem unit test test macro does not work well

Hi I am trying to decide on what to use for unit testing. So, I was trying the FievAM package from [..] I created the following (actually I ran into this issue and...

Antony Sequeira
detecting running under UNIT TEST

Hi there, I use Visual Studio 2005, c# projects... I like the new unit test framework very much, it helps a lot mantaining and growing up a project with the test driven...

Ing. Davide Piras
Running one test with test/unit

Hi, As per this page[1], it is possible to run one test from a testcase by using.. # ruby [programfile] -n [testmethod] I'm probably missing something obvious but I really...

Chris Roos

Privacy Policy | All times are GMT. The time now is 12:35 PM.

Merging Information Logo
[Deutschland] [España] [France] [Italia] [Nederland] [Polska] [United Kingdom]