org.scalatest.junit

class JUnitTestFailedError

[source: org/scalatest/junit/JUnitTestFailedError.scala]

class JUnitTestFailedError(val message : scala.Option[java.lang.String], val cause : scala.Option[java.lang.Throwable], val failedCodeStackDepth : Int)
extends junit.framework.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.

Parameters
message - an optional detail message for this TestFailedException.
cause - an optional cause, the Throwable that caused this TestFailedException to be thrown.
failedCodeStackDepth - the depth in the stack trace of this exception at which the line of test code that failed resides.
Throws
NullPointerException - if message is null, or Some(null).
NullPointerException - if cause is null, or Some(null).
Author
Bill Venners
Additional Constructor Summary
def this (message : java.lang.String, failedCodeStackDepth : Int) : JUnitTestFailedError
Create a JUnitTestFailedError with a specified stack depth and detail message.
def this (message : java.lang.String, cause : java.lang.Throwable, failedCodeStackDepth : Int) : JUnitTestFailedError
Create a JUnitTestFailedError with the specified stack depth, detail message, and cause.
def this (failedCodeStackDepth : Int) : JUnitTestFailedError
Create a JUnitTestFailedError with specified stack depth and no detail message or cause.
def this (cause : java.lang.Throwable, failedCodeStackDepth : Int) : JUnitTestFailedError
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.
Values and Variables inherited from StackDepth
failedCodeFileNameAndLineNumberString
Method Summary
override final def initCause (throwable : java.lang.Throwable) : java.lang.Throwable
Methods inherited from java.lang.Throwable
java.lang.Throwable.getMessage, java.lang.Throwable.getLocalizedMessage, java.lang.Throwable.getCause, java.lang.Throwable.toString, java.lang.Throwable.printStackTrace, java.lang.Throwable.printStackTrace, java.lang.Throwable.printStackTrace, java.lang.Throwable.fillInStackTrace, java.lang.Throwable.getStackTrace, java.lang.Throwable.setStackTrace
Methods inherited from AnyRef
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this(failedCodeStackDepth : Int) : JUnitTestFailedError
Create a JUnitTestFailedError with specified stack depth and no detail message or cause.
Parameters
failedCodeStackDepth - the depth in the stack trace of this exception at which the line of test code that failed resides.

def this(message : java.lang.String, failedCodeStackDepth : Int) : JUnitTestFailedError
Create a JUnitTestFailedError with a specified stack depth and detail message.
Parameters
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.
Throws
NullPointerException - if message is null.

def this(cause : java.lang.Throwable, failedCodeStackDepth : Int) : JUnitTestFailedError
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.
Parameters
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.
Throws
NullPointerException - if cause is null.

def this(message : java.lang.String, cause : java.lang.Throwable, failedCodeStackDepth : Int) : JUnitTestFailedError
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.

Parameters
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.
Throws
NullPointerException - if message is null.
NullPointerException - if cause is null.

Method Details
override final def initCause(throwable : java.lang.Throwable) : java.lang.Throwable


Copyright (C) 2001-2010 Artima, Inc. All rights reserved.