Hi Niko,
On Fri, Jun 19, 2009 at 12:37 PM, Niko Matsakis <
nikoma...@gmail.com> wrote:
>
> Hmm, it occurs to me that I could perhaps write some code like:
> def withDebug(testFunction: StringBuffer => Unit) {
> val buffer = new StringBuffer()
> try {
> testFunction(buffer)
> } catch {
> case t: Throwable =>
> info(buffer.toString)
> throw t
> }
> }
>
> Now, assuming I managed to arrange for my debug output to be channeled into the buffer, I would only get printouts if the test failed. This is acting on the assumption that scala test verification methods throw exceptions on failure, which I believe is true, no?
> Kind of similar to what you suggested as an alternate to tearDown here:
http://www.artima.com/weblogs/viewpost.jsp?thread=232028
>
Yes, that would work, so long as you're using FunSuite (Spec doesn't
have info() in 0.9.5. If you're using Spec, though, you can do info
yourself. Let me know if that's what you're doing and I'll show how
you can do it in 0.9.5 with Spec. Spec will have info in 0.9.6.). Your
captured debug info would show up just above the info for the failed
test in the report.
ScalaTest does use the same, traditional
throw-an-exception-to-indicate-test-failure in Suite, FunSuite, Spec,
etc. This allows people to use JUnit or TestNG assertions if they
prefer, or ScalaTest Assertions, MustMatchers, or ShouldMatchers, or
Specs Matchers. Also any kind of unexpected exception will cause a
test failure. When you use one of the ScalaTest options for assertions
or matchers, the exception that is thrown in called
TestFailedException, and it includes a nice bit of information
pointing to exactly the line of code test that caused the failure,
which saves you from scanning through the stack trace for it.
Thanks.
Bill