org.scalatest.junit

JUnitTestFailedError

class JUnitTestFailedError extends AssertionFailedError with StackDepth with ModifiableMessage[JUnitTestFailedError]

Exception that indicates a test failed.

The purpose of this exception is to encapsulate the same stack depth information provided byTestFailedException, which is used when running with ScalaTest, but be reported as a failure not an error when running with JUnit. The stack depth information indicates which line of test code failed, so that when running with ScalaTest information can be presented to the user that makes it quick to find the failing line of test code. (In other words, when running with ScalaTest the user need not scan through the stack trace to find the correct filename and line number of the failing test.)

JUnit distinguishes between failures and errors. If a test fails because of a failed assertion, that is considered a failure in JUnit. If a test fails for any other reason, either the test code or the application being tested threw an unexpected exception, that is considered an error in JUnit. This class differs fromTestFailedException in that it extendsjunit.framework.AssertionFailedError. Instances of this class are thrown by the assertions provided by AssertionsForJUnit, and matcher expressions provided by ShouldMatchersForJUnit, andMustMatchersForJUnit.

The way JUnit 3 (JUnit 3.8 and earlier releases) decided whether an exception represented a failure or error is that only thrown junit.framework.AssertionFailedErrors were considered failures. Any other exception type was considered an error. The exception type thrown by the JUnit 3 assertion methods declared in junit.framework.Assert (such as assertEquals, assertTrue, and fail) was, therefore, AssertionFailedError. In JUnit 4, AssertionFailedErrorwas made to extend java.lang.AssertionError, and the distinction between failures and errors was essentially dropped. However, some tools that integrate with JUnit carry on this distinction, so even if you are using JUnit 4 you may want to use the "ForJUnit" of ScalaTest assertions and matchers.

    authors:
  1. Bill Venners

Inherited
  1. Hide All
  2. Show all
  1. ModifiableMessage
  2. StackDepth
  3. AssertionFailedError
  4. AssertionError
  5. Error
  6. Throwable
  7. Serializable
  8. AnyRef
  9. Any
Visibility
  1. Public
  2. All

Instance constructors

  1. new JUnitTestFailedError(message: String, cause: Throwable, failedCodeStackDepth: Int)

    Create a JUnitTestFailedError with the specified stack depth, detail message, and cause.

  2. new JUnitTestFailedError(cause: Throwable, failedCodeStackDepth: Int)

    Create a JUnitTestFailedError with the specified stack depth and cause.

  3. new JUnitTestFailedError(message: String, failedCodeStackDepth: Int)

    Create a JUnitTestFailedError with a specified stack depth and detail message.

  4. new JUnitTestFailedError(failedCodeStackDepth: Int)

    Create a JUnitTestFailedError with specified stack depth and no detail message or cause.

  5. new JUnitTestFailedError(message: Option[String], cause: Option[Throwable], failedCodeStackDepth: Int)

Value Members

  1. def !=(arg0: AnyRef): Boolean

  2. def !=(arg0: Any): Boolean

    o != arg0 is the same as !(o == (arg0)).

  3. def ##(): Int

  4. def $asInstanceOf[T0](): T0

  5. def $isInstanceOf[T0](): Boolean

  6. def ==(arg0: AnyRef): Boolean

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

  7. def ==(arg0: Any): Boolean

    o == arg0 is the same as o.equals(arg0).

  8. def asInstanceOf[T0]: T0

    This method is used to cast the receiver object to be of type T0.

  9. def canEqual(other: Any): Boolean

    Indicates whether this object can be equal to the passed object.

  10. val cause: Option[Throwable]

    An optional cause, the Throwable that caused this StackDepth exception to be thrown.

  11. def clone(): AnyRef

    This method creates and returns a copy of the receiver object.

  12. def eq(arg0: AnyRef): Boolean

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

  13. def equals(other: Any): Boolean

    Indicates whether this object is equal to the passed object.

  14. def failedCodeFileNameAndLineNumberString: Option[String]

    A string that provides the filename and line number of the line of code that failed, suitable for presenting to a user, which is taken from this exception's StackTraceElement at the depth specified by failedCodeStackDepth.

  15. val failedCodeStackDepth: Int

    The depth in the stack trace of this exception at which the line of test code that failed resides.

  16. def fillInStackTrace(): Throwable

  17. def finalize(): Unit

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

  18. def getCause(): Throwable

  19. def getClass(): java.lang.Class[_]

    Returns a representation that corresponds to the dynamic class of the receiver object.

  20. def getLocalizedMessage(): String

  21. def getMessage(): String

  22. def getStackTrace(): Array[StackTraceElement]

  23. def hashCode(): Int

    Returns a hash code value for this object.

  24. def initCause(throwable: Throwable): Throwable

  25. def isInstanceOf[T0]: Boolean

    This method is used to test whether the dynamic type of the receiver object is T0.

  26. val message: Option[String]

    An optional detail message for this StackDepth exception.

  27. def modifyMessage(fun: (Option[String]) ⇒ Option[String]): JUnitTestFailedError

    Returns an instance of this exception's class, identical to this exception, except with the detail message option string replaced with the result of passing the current detail message to the passed function, fun.

  28. def ne(arg0: AnyRef): Boolean

    o.ne(arg0) is the same as !(o.eq(arg0)).

  29. def notify(): Unit

    Wakes up a single thread that is waiting on the receiver object's monitor.

  30. def notifyAll(): Unit

    Wakes up all threads that are waiting on the receiver object's monitor.

  31. def printStackTrace(arg0: PrintWriter): Unit

  32. def printStackTrace(arg0: PrintStream): Unit

  33. def printStackTrace(): Unit

  34. def setStackTrace(arg0: Array[StackTraceElement]): Unit

  35. def severedAtStackDepth: JUnitTestFailedError

    Returns an exception of class JUnitTestFailedError with failedExceptionStackDepth set to 0 and all frames above this stack depth severed off.

  36. def synchronized[T0](arg0: T0): T0

  37. def toString(): String

    Returns a string representation of the object.

  38. def wait(): Unit

  39. def wait(arg0: Long, arg1: Int): Unit

  40. def wait(arg0: Long): Unit