Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Tests w/ Full Stack Traces

This seems like a stupid question, but I could not find the answer anywhere. I am using Rails 3.1 with Test::Unit.

When a test fails I only see the top of the stack, e.g.:

ERROR creating a message sends emails (1.35s) 
          NoMethodError: undefined method `project' for nil:NilClass
      /Users/ghempton/.rvm/gems/ruby-1.9.2-p180@gt/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing'

How do I see the full stack trace?

like image 550
ghempton Avatar asked Feb 09 '12 21:02

ghempton


People also ask

What is meant by stack traces?

In computing, a stack trace (also called stack backtrace or stack traceback) is a report of the active stack frames at a certain point in time during the execution of a program. When a program is run, memory is often dynamically allocated in two places; the stack and the heap.

Should unit tests be self contained?

Every single unit test should be self-contained and not depend on others. Don't repeat yourself.

Should unit tests be in the same package?

Unit tests can be in any package. In essence they are just separate classes used to test the behaviour of the class being tested.

How often should unit tests be executed?

Your answers confirm my general conclusion that running all unit tests after every local rebuild is the best practice regardless whether one is practicing TDD (test before) or classic unit testing (test after).


2 Answers

uncomment the following line in config/initializers/backtrace_silencers.rb:

Rails.backtrace_cleaner.remove_silencers!

funny that we've lived with this helpful option so long, I even forgot about it! :-)

like image 118
Kevin Triplett Avatar answered Sep 27 '22 18:09

Kevin Triplett


I wound up fixing this by updating the turn gem which formats the test output.

like image 29
ghempton Avatar answered Sep 27 '22 16:09

ghempton