Hi Cay,
On Sun, Sep 20, 2009 at 9:33 PM, Cay Horstmann <
c...@horstmann.com> wrote:
>
> Thanks very much! It works like a charm for me. My students will be
> delighted--I originally had them go back to 2.7.6, and that version's
> Eclipse plugin seems to have more problems than the latest one.
>
> ScalaTest has worked out very nicely for me for grading homework :-) I
> really enjoyed the fact that I was able to choose the testing style
> that was best for my situation.
>
> Just one question--how do I suppress the exception trace when an
> assertion fails? I mean, if I get a report that foo isn't actually
> bar, that's good enough for me. I don't care to see the life story of
> the test runner.
>
Which reporter or reporters are you using? The only ones in which the
stack trace can really get in your face is the standard out, standard
err, or file reporters.
The story of stack traces is that I wanted to try and save people from
needing to scan through them to find the line of code for failed
tests, because that slows people down. When an assertion or matcher
expression fails, it does so with a TestFailedException, which mixes
in trait StackDepth. A StackDepth exception contains an integer stack
depth which is the index in the stack trace array of the line of code
of the failed assertion. There are other StackDepthExceptions as well,
JUnitTestFailedError for when you're using JUnit,
DuplicateTestNameException, etc. The reporters highlight the file name
and line number of the offending line of test code so you don't have
to scan, when the exception is a StackDepth. If it isn't a StackDepth,
such as if the code under test through some random exception, then the
reporters can only give you the stack trace.
However, I also show at least a truncated stack trace in the case of
StackDepths, because what can happen is you may factor out duplicate
code into a method. The method has an assertion that may fail, and if
you don't have any stack trace, you won't know which call site failed.
For example I have this helper method:
def ensureTestFailedEventReceived(suite: Suite, testName: String) {
val reporter = new EventRecordingReporter
suite.run(None, reporter, new Stopper {}, Filter(), Map(), None,
new Tracker)
val testFailedEvent =
reporter.eventsReceived.find(_.isInstanceOf[TestFailed])
assert(testFailedEvent.isDefined)
assert(testFailedEvent.get.asInstanceOf[TestFailed].testName === testName)
}
If the second assertion fails, the stack depth will point to that
assertion. I'll also get the name of the test that failed, but I'll
still want to know more if I call this helper method multiple times
from the same test, like this:
test("something") {
// ...
ensureTestFailedEventReceived(spec1, "should blow up")
// ...
ensureTestFailedEventReceived(spec2, "should blow up")
}
Which one of these was the one that failed? spec1 or spec2? So that's
why I show around 7 lines of stack trace in the standard out, standard
err, and file reporters for StackDepth exceptions. I cut off the top,
which is above the stack depth, show the next seven lines of stack
trace, then truncate the rest. I'm figuring you'd have to do a lot of
factoring out into helper methods for those 7 lines of code to not be
enough.
If it isn't a StackDepth exception, you get the whole stack trace, and
if someone always want full stack traces, you can configure that by
adding a config param F to the reporter arg, like a -oF on the command
line will get you a standard out reporter that always shows full stack
traces for everything.
By the way, what RSpec, a Ruby BDD tool, does is put a footnote next
to a failure message, and then show the stack trace at the bottom.
When doing BDD like tests, a stack trace can make the output a bit
ugly. But I think when you have a failing test you really want to know
the info as quickly as possible, so I didn't want you to have to scan
for footnotes. By truncating it most of the time, my hope was that you
get quick access to the info without completely cluttering up your
nice spec-like output.
Bill
> Thanks,
>
> Cay
>
> On Sep 20, 7:21 pm, Bill Venners <
b...@artima.com> wrote:
>> Hi All,
>>
>> I just released a fresh ScalaTest 1.0 snapshot, both for 2.7.5 and the
>> latest nightly 2.8 build...If you have time please give it
>> a test drive and post feedback to scalatest-users.
>
> >
>
--