org.scalatest.junit

JUnitTestFailedError

class JUnitTestFailedError extends AssertionFailedError with StackDepth

Exception that indicates a test failed.

The purpose of this exception is to encapsulate the same stack depth information provided by TestFailedException, 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 from TestFailedException in that it extends junit.framework.AssertionFailedError. Instances of this class are thrown by the assertions provided by AssertionsForJUnit, and matcher expressions provided by ShouldMatchersForJUnit, and MustMatchersForJUnit.

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, AssertionFailedError was 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.

Inherits

  1. StackDepth
  2. AssertionFailedError
  3. AssertionError
  4. Error
  5. Throwable
  6. Serializable
  7. AnyRef
  8. Any

Value Members

  1. val cause: Option[Throwable]

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

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

  2. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    The default implementations of this method is an equivalence relation:

    • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
    • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
    • It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

    If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same Int (o1.hashCode.equals(o2.hashCode)).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    definition classes: AnyRef ⇐ Any
  3. val 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

    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.

    definition classes: StackDepth
  4. val failedCodeStackDepth: Int

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

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

  5. def fillInStackTrace(): Throwable

  6. def getCause(): Throwable

  7. def getLocalizedMessage(): String

  8. def getMessage(): String

  9. def getStackTrace(): Array[StackTraceElement]

  10. def hashCode(): Int

    Returns a hash code value for the object

    Returns a hash code value for the object.

    The default hashing algorithm is platform dependent.

    Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

    definition classes: AnyRef ⇐ Any
  11. val message: Option[String]

    An optional detail message for this StackDepth exception

    An optional detail message for this StackDepth exception.

  12. def printStackTrace(arg0: PrintWriter): Unit

  13. def printStackTrace(arg0: PrintStream): Unit

  14. def printStackTrace(): Unit

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

  16. def toString(): String

    Returns a string representation of the object

    Returns a string representation of the object.

    The default representation is platform dependent.

    definition classes: Throwable ⇐ AnyRef ⇐ Any

Instance constructors

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

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

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

    Note that the detail message associated with cause is not automatically incorporated in this throwable's detail message.

    message

    A detail message for this JUnitTestFailedError.

    cause

    the cause, the Throwable that caused this JUnitTestFailedError to be thrown.

    failedCodeStackDepth

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

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

    Create a JUnitTestFailedError with the specified stack depth and cause

    Create a JUnitTestFailedError with the specified stack depth and cause. The message field of this exception object will be initialized to if (cause.getMessage == null) "" else cause.getMessage.

    cause

    the cause, the Throwable that caused this JUnitTestFailedError to be thrown.

    failedCodeStackDepth

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

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

    Create a JUnitTestFailedError with a specified stack depth and detail message

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

    message

    A detail message for this JUnitTestFailedError.

    failedCodeStackDepth

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

  4. new JUnitTestFailedError(failedCodeStackDepth: Int)

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

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

    failedCodeStackDepth

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

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

  6. new JUnitTestFailedError(arg0: String)

  7. new JUnitTestFailedError()

  8. new JUnitTestFailedError(arg0: Double)

  9. new JUnitTestFailedError(arg0: Float)

  10. new JUnitTestFailedError(arg0: Long)

  11. new JUnitTestFailedError(arg0: Char)

  12. new JUnitTestFailedError(arg0: Boolean)

  13. new JUnitTestFailedError(arg0: Any)

  14. new JUnitTestFailedError(arg0: Throwable)

  15. new JUnitTestFailedError(arg0: String, arg1: Throwable)