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.
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.
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.
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.
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.