Debugging and Test::Unit

Hi,

I often find I want to step through my test code
with the debugger. But using Test::Unit and invoking
the debugger as

ruby -r debug example_test.rb

and setting a breakpoint on the line I want to start
debugging on don’t work; the debugger simply
finished without breaking.

How can I deal with that?

example_test.rb:

···

require ‘test/unit’

class MTC < Test::Unit::TestCase
def test_01
a = 1 # Lets break here!
end
end

and then

$ ruby -r debug example_test.rb
Debug.rb
Emacs support available.

example_test.rb:1:require ‘test/unit’
(rdb:1) b 5
Set breakpoint 1 at example_test.rb:5
(rdb:1) c
Loaded suite example_test
Started…

Finished in 0.031 seconds.
1 runs, 0 assertions, 0 failures, 0 errors

ie. I never get to debug…

Thanks,

Karsten


http://fastmail.fm - Access your email from home and the web

Hi,

I often find I want to step through my test code
with the debugger. But using Test::Unit and invoking
the debugger as

ruby -r debug example_test.rb

and setting a breakpoint on the line I want to start
debugging on don’t work; the debugger simply
finished without breaking.

How can I deal with that?

Good timing. I’m maintaing a list of debugger problems at

http://www.rubygarden.org/ruby?RubyDebuggerProblems

This is a known problem, and there’s no (yet) known solution. This is probably
because Test::Unit relies on at_exit in order to actually run the tests, and
perhaps the debugger can’t trap things from within at_exit.

Maybe if you defined an explicit test runner within the Test::Unit framework
this problem would be avoided. I’ll try this as well if it’s possible.

Anyway, I’ve used your example on the Wiki page, which lacked one for this
problem.

Gavin

···

From: coma_killen@fastmail.fm

From: coma_killen@fastmail.fm

Hi,

I often find I want to step through my test code
with the debugger. But using Test::Unit and invoking
the debugger as

ruby -r debug example_test.rb

and setting a breakpoint on the line I want to start
debugging on don’t work; the debugger simply
finished without breaking.

How can I deal with that?

Good timing. I’m maintaing a list of debugger problems at

http://www.rubygarden.org/ruby?RubyDebuggerProblems

This is a known problem, and there’s no (yet) known solution. This is
probably
because Test::Unit relies on at_exit in order to actually run the tests,
and
perhaps the debugger can’t trap things from within at_exit.

Maybe if you defined an explicit test runner within the Test::Unit framework
this problem would be avoided. I’ll try this as well if it’s possible.

This works!

At the bottom of my test file (say the test class is called TC_Foo), I placed
the lines:

require ‘test/unit/ui/console/testrunner’
Test::Unit::UI::Console::TestRunner.run(TC_Foo)

This runs just the same as if you didn’t have it, because the at_exit code
would have run this anyway. I regard this as a workaround for now, because
although it’s not difficult, it’s a minor hassle to do this when you want to
debug.

Note: TestUnit seems to run quite slowly under the debugger. However, the
machine I’m running it on it slow anyway (even though it’s a production server)
so YMMV.

Gavin

···

From: “Gavin Sinclair” gsinclair@soyabean.com.au