Question

I'm getting stack traces when a ScalaTest test fails in SBT. I've tried set traceLevel in Test := -1 at the SBT prompt, tried changing things in the build.sbt file, etc., but nothing seems to help.

What I'd like to get rid of is this:

> test
[info] TestWritingFunctions:
[info] - threeSquares examples *** FAILED ***
[info]   scala.NotImplementedError: an implementation is missing
[info]   at scala.Predef$.$qmark$qmark$qmark(Predef.scala:252)
[info]   at TestWritingFunctions$$anonfun$1.apply$mcV$sp(WritingFunctions.scala:17)
[info]   at TestWritingFunctions$$anonfun$1.apply(WritingFunctions.scala:16)
[info]   at TestWritingFunctions$$anonfun$1.apply(WritingFunctions.scala:16)
[info]   at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
[info]   at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
[info]   ...

As you can see, the test is failing because I used the new ??? construct as a placeholder, but since I know there's a placeholder there, I'd just like a *** FAILED *** message without all the rigamarole. Is that possible?

Was it helpful?

Solution

You can use "-o..." without F or S (i.e, "-o" or "-oD" would give you no stack traces, but not "-oF", "-oS", or "-oDS" would give you a stack trace). That means you'd be suppressing all stack traces. If you specify no reporters at all, you'll get a "-o", which means no stack traces.

If you like the short stack traces in general, but don't want to see them when a NotImplementedError is thrown by ???, you can override withFixture and change NotImplementedError into pending tests:

import org.scalatest._

trait PendingIfUnimplemented extends SuiteMixin { this: Suite =>

  abstract override def withFixture(test: NoArgTest): Outcome = {
    super.withFixture(test) match {
      case Failed(ex: NotImplementedError) => Pending
      case other => other 
    }
  }
}

This way you'll still get short, long, or no stack traces for regular failures, whatever you chose, but see (pending) for tests that fail because of ???.

OTHER TIPS

(not authoritative, but since no one else has answered:)

I suspect that traceLevel isn't doing anything because the stack traces are coming from ScalaTest, not from sbt.

sbt does have a logLevel setting which is relevant. Try this:

set logLevel in Test := Level.Warn

But note that this suppresses not only the stack traces, but all of the lines in your example that begin with [info]. Instead, you'll just get the [error] stuff at the end, which does at least have the names of the suites with failing tests.

If you really want to only suppress the stack traces without changing anything else, I think that might not be possible. Looking at http://www.scalatest.org/user_guide/using_the_runner , I see options for making stack traces shorter (-oS) or longer (-oF), but no option for omitting the stack trace altogether.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top