How to debug unit (and other) tests?

I’m sorry if this sounds like a totally newbie question, but…

Are there good tips and resources for debugging unit tests?
Currently, I just fire up script/console using the “test” environment
and just poke around randomly until I hit upon some inspiration. But
I think there should be a better way, for example, it would be nice to
single step through a particular test case using a debugger in one
window and watching the test log in the other window.

Any tips?

Thanks.

–wpd

Patrick D. wrote:

I’m sorry if this sounds like a totally newbie question, but…

Are there good tips and resources for debugging unit tests?
Currently, I just fire up script/console using the “test” environment
and just poke around randomly until I hit upon some inspiration. But
I think there should be a better way, for example, it would be nice to
single step through a particular test case using a debugger in one
window and watching the test log in the other window.

Any tips?

Just call the debugger from within your app code, or from the test
itself. When the “debug” statement is executed, you’ll be in an
interactive debugger. Simple.

Thanks.

–wpd

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Wed, Oct 7, 2009 at 10:33 AM, Marnen Laibow-Koser
[email protected] wrote:

Just call the debugger from within your app code, or from the test
itself. When the “debug” statement is executed, you’ll be in an
interactive debugger. Simple.

“debug” is for use with views, and does not stop execution.

<%= debug @foo %>

“debugger” is for actually invoking the debugger and stopping execution.


Greg D.
http://destiney.com/

On Wed, Oct 7, 2009 at 11:33 AM, Marnen Laibow-Koser
[email protected] wrote:

Patrick D. wrote:

Are there good tips and resources for debugging unit tests?

Just call the debugger from within your app code, or from the test
itself. When the “debug” statement is executed, you’ll be in an
interactive debugger. Simple.

I’m missing something because it is not simple…

class LotTest < ActiveSupport::TestCase

test “add lot to assembly” do
debug

end
end

When I try running this as:

$ ruby -I test test/unit/lot_test.rb -n test_add_lot_to_assembly

the test fails with:

NameError: undefined local variable or method `debug’ for …

When I try running this as:

$ rdebug -I test test/unit/lot_test.rb -n test_add_lot_to_assembly
(rdb:1) c

The test runs to completion and doesn’t stop at my #debug statement.

I won’t even go into my trials and tribulations trying to get this to
run under emacs…

I agree though, this should really be simple. Having said that, I
must be missing something terribly obvious.

–wpd

On Wed, Oct 7, 2009 at 12:45 PM, Colin L. [email protected]
wrote:

2009/10/7 Patrick D. [email protected]:

Are there good tips and resources for debugging unit tests?

Have a look at the rails guide on debugging. Particularly the section
on ruby-debug.

Thanks. That’s what I was looking for.

Now, if I could just get it to interact sanely with Emacs, I’d be a
happy camper :slight_smile:

–wpd

2009/10/7 Patrick D. [email protected]:

I’m sorry if this sounds like a totally newbie question, but…

Are there good tips and resources for debugging unit tests?
Currently, I just fire up script/console using the “test” environment
and just poke around randomly until I hit upon some inspiration. Â But
I think there should be a better way, for example, it would be nice to
single step through a particular test case using a debugger in one
window and watching the test log in the other window.

Have a look at the rails guide on debugging. Particularly the section
on ruby-debug.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs