TestFailedException

org.scalatest.exceptions.TestFailedException
class TestFailedException(messageFun: StackDepthException => Option[String], cause: Option[Throwable], posOrStackDepthFun: Either[Position, StackDepthException => Int], val payload: Option[Any], val analysis: IndexedSeq[String]) extends StackDepthException, ModifiableMessage[TestFailedException], PayloadField, ModifiablePayload[TestFailedException]

Exception that indicates a test failed.

One purpose of this exception is to encapsulate information about the stack depth at which the line of test code that failed resides, so that information can be presented to the user that makes it quick to find the failing line of test code. (In other words, the user need not scan through the stack trace to find the correct filename and line number of the failing test.)

Another purpose of this exception is to encapsulate a payload, an object to be included in a TestFailed event as its payload, so it can be consumed by a custom reporter that understands the payload. For example, tests could take a screen shot image of a GUI when a test fails, and include that as a payload. A custom reporter could listen for such payloads and display the screen shots to the user.

Value parameters

cause

an optional cause, the Throwable that caused this TestFailedException to be thrown.

messageFun

a function that produces an optional detail message for this TestFailedException.

payload

an optional payload, which ScalaTest will include in a resulting TestFailed event

posOrStackDepthFun

a source position or a function that produces the depth in the stack trace of this exception at which the line of test code that failed resides.

Attributes

Throws
NullArgumentException

if either messageFun, cause or failedCodeStackDepthFun is null, or Some(null).

Graph
Supertypes
trait PayloadField
trait StackDepth
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes

Members list

Value members

Constructors

def this(messageFun: StackDepthException => Option[String], cause: Option[Throwable], pos: Position, payload: Option[Any])

Constructs a TestFailedException with the given error message function, optional cause, source position and optional payload.

Constructs a TestFailedException with the given error message function, optional cause, source position and optional payload.

Value parameters

cause

an optional cause, the Throwable that caused this TestFailedException to be thrown.

messageFun

a function that return an optional detail message for this TestFailedException.

payload

an optional payload, which ScalaTest will include in a resulting TestFailedException event

pos

a source position

Attributes

def this(messageFun: StackDepthException => Option[String], cause: Option[Throwable], pos: Position)

Constructs a TestFailedException with the given error message function, optional cause and source position.

Constructs a TestFailedException with the given error message function, optional cause and source position.

Value parameters

cause

an optional cause, the Throwable that caused this TestFailedException to be thrown.

messageFun

a function that return an optional detail message for this TestFailedException.

pos

a source position

Attributes

def this(messageFun: StackDepthException => Option[String], cause: Option[Throwable], failedCodeStackDepthFun: StackDepthException => Int)

Constructs a TestFailedException with pre-determined message and failedCodeStackDepth. (This was the primary constructor form from ScalaTest 1.5 to 1.8.)

Constructs a TestFailedException with pre-determined message and failedCodeStackDepth. (This was the primary constructor form from ScalaTest 1.5 to 1.8.)

Value parameters

cause

an optional cause, the Throwable that caused this TestFailedException to be thrown.

failedCodeStackDepthFun

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

messageFun

a function that produces an optional detail message for this TestFailedException.

Attributes

Throws
NullArgumentException

if either message of cause is null, or Some(null).

def this(message: Option[String], cause: Option[Throwable], failedCodeStackDepth: Int)

Constructs a TestFailedException with pre-determined message and failedCodeStackDepth. (This was the primary constructor form prior to ScalaTest 1.5.)

Constructs a TestFailedException with pre-determined message and failedCodeStackDepth. (This was the primary constructor form prior to ScalaTest 1.5.)

Value parameters

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.

message

an optional detail message for this TestFailedException.

Attributes

Throws
NullArgumentException

if either message of cause is null, or Some(null).

def this(failedCodeStackDepth: Int)

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

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

Value parameters

failedCodeStackDepth

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

Attributes

def this(message: String, failedCodeStackDepth: Int)

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

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

Value parameters

failedCodeStackDepth

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

message

A detail message for this TestFailedException.

Attributes

Throws
NullArgumentException

if message is null.

def this(cause: Throwable, failedCodeStackDepth: Int)

Create a TestFailedException 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.

Create a TestFailedException 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.

Value parameters

cause

the 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.

Attributes

Throws
NullArgumentException

if cause is null.

def this(message: String, cause: Throwable, failedCodeStackDepth: Int)

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

Create a TestFailedException 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.

Value parameters

cause

the 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.

message

A detail message for this TestFailedException.

Attributes

Throws
NullArgumentException

if either message or cause is null.

def this(messageFun: StackDepthException => Option[String], cause: Option[Throwable], failedCodeStackDepthFun: StackDepthException => Int, payload: Option[Any])

Constructs a TestFailedException with the given error message function, optional cause, stack depth function and optional payload.

Constructs a TestFailedException with the given error message function, optional cause, stack depth function and optional payload.

Value parameters

cause

an optional cause, the Throwable that caused this TestFailedException to be thrown.

failedCodeStackDepthFun

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

messageFun

a function that return an optional detail message for this TestFailedException.

payload

an optional payload, which ScalaTest will include in a resulting TestFailedException event

Attributes

Concrete methods

override def canEqual(other: Any): Boolean

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

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

Attributes

Definition Classes
override def equals(other: Any): Boolean

Indicates whether this object is equal to the passed object. If the passed object is a TestFailedException, equality requires equal message, cause, and failedCodeStackDepth fields, as well as equal return values of getStackTrace.

Indicates whether this object is equal to the passed object. If the passed object is a TestFailedException, equality requires equal message, cause, and failedCodeStackDepth fields, as well as equal return values of getStackTrace.

Attributes

Definition Classes
override def hashCode: Int

Returns a hash code value for this object.

Returns a hash code value for this object.

Attributes

Definition Classes
def modifyMessage(fun: Option[String] => Option[String]): TestFailedException

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.

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.

Value parameters

fun

A function that, given the current optional detail message, will produce the modified optional detail message for the result instance of TestFailedException.

Attributes

def modifyPayload(fun: Option[Any] => Option[Any]): TestFailedException

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

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

Value parameters

fun

A function that, given the current optional payload, will produce the modified optional payload for the result instance of TestFailedException.

Attributes

Returns an exception of class TestFailedException with failedExceptionStackDepth set to 0 and all frames above this stack depth severed off. This can be useful when working with tools (such as IDEs) that do not directly support ScalaTest. (Tools that directly support ScalaTest can use the stack depth information delivered in the StackDepth exceptions.)

Returns an exception of class TestFailedException with failedExceptionStackDepth set to 0 and all frames above this stack depth severed off. This can be useful when working with tools (such as IDEs) that do not directly support ScalaTest. (Tools that directly support ScalaTest can use the stack depth information delivered in the StackDepth exceptions.)

Attributes

Inherited methods

final def addSuppressed(x$0: Throwable): Unit

Attributes

Inherited from:
Throwable
def failedCodeFileName: Option[String]

A string that provides the filename 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 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.

This is a def instead of a val because exceptions are mutable: their stack trace can be changed after the exception is created. This is done, for example, by the SeveredStackTraces trait.

Attributes

Returns

a string containing the filename that caused the failed test

Inherited from:
StackDepth

A string that provides the filename and line number of the line of code that failed, suitable for presenting to a user of the failing line. It calls failedCodeFileName and failedCodeLineNumber to get the failing filename and line number.

A string that provides the filename and line number of the line of code that failed, suitable for presenting to a user of the failing line. It calls failedCodeFileName and failedCodeLineNumber to get the failing filename and line number.

failedCodeFileName and failedCodeLineNumber will fall back to exception stack trace when Position is not avaiable, this is the reason it is a def instead of a val, because exceptions are mutable: their stack trace can be changed after the exception is created. This is done, for example, by the SeveredStackTraces trait.

Attributes

Returns

a user-presentable string containing the filename and line number that caused the failed test

Inherited from:
StackDepth
def failedCodeLineNumber: Option[Int]

A string that provides the 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 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.

This is a def instead of a val because exceptions are mutable: their stack trace can be changed after the exception is created. This is done, for example, by the SeveredStackTraces trait.

Attributes

Returns

a string containing the line number that caused the failed test

Inherited from:
StackDepth
def fillInStackTrace(): Throwable

Attributes

Inherited from:
Throwable
def getCause(): Throwable

Attributes

Inherited from:
Throwable
def getLocalizedMessage(): String

Attributes

Inherited from:
Throwable
override def getMessage: String

Returns the detail message string of this StackDepthException.

Returns the detail message string of this StackDepthException.

Attributes

Returns

the detail message string of this StackDepthException instance (which may be null).

Definition Classes
StackDepthException -> Throwable
Inherited from:
StackDepthException
def getStackTrace(): Array[StackTraceElement]

Attributes

Inherited from:
Throwable
final def getSuppressed(): Array[Throwable]

Attributes

Inherited from:
Throwable
final override def initCause(throwable: Throwable): Throwable

Attributes

Definition Classes
StackDepthException -> Throwable
Inherited from:
StackDepthException
def printStackTrace(x$0: PrintWriter): Unit

Attributes

Inherited from:
Throwable
def printStackTrace(x$0: PrintStream): Unit

Attributes

Inherited from:
Throwable
def printStackTrace(): Unit

Attributes

Inherited from:
Throwable
def setStackTrace(x$0: Array[StackTraceElement]): Unit

Attributes

Inherited from:
Throwable
def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Inherited from:
Throwable

Concrete fields

val analysis: IndexedSeq[String]
val payload: Option[Any]

The optional payload.

The optional payload.

Attributes

Inherited fields

lazy val failedCodeFilePathname: Option[String]

A string that provides the full pathname of the source file containing the line of code that failed, suitable for presenting to a user.

A string that provides the full pathname of the source file containing the line of code that failed, suitable for presenting to a user.

Attributes

Returns

a string containing the full pathname of the source file containing the line of code that caused this exception

Inherited from:
StackDepthException

A string that provides the absolute filename and line number of the line of code that failed, suitable for presenting to a user of the failing line. It calls failedCodeFilePathname and failedCodeLineNumber to get the failing absolute filename and line number.

A string that provides the absolute filename and line number of the line of code that failed, suitable for presenting to a user of the failing line. It calls failedCodeFilePathname and failedCodeLineNumber to get the failing absolute filename and line number.

Attributes

Returns

a user-presentable string containing the absolute filename and line number that caused the failed test

Inherited from:
StackDepth
lazy 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.

One reason this is lazy is to delay any searching of the stack trace until it is actually needed. It will usually be needed, but not always. For example, exceptions thrown during a shrink phase of a failed property will often be StackDepthExceptions, but whose failedCodeStackDepth will never be used. Another reason is to remove the need to create a different exception before creating this one just for the purpose of searching through its stack trace for the proper stack depth. Still one more reason is to allow the message to contain information about the stack depth, such as the failed file name and line number.

Attributes

Inherited from:
StackDepthException
lazy val message: Option[String]

An optional detail message for this StackDepth exception.

An optional detail message for this StackDepth exception.

One reason this is lazy is to delay any searching of the stack trace until it is actually needed. It will usually be needed, but not always. For example, exceptions thrown during a shrink phase of a failed property will often be StackDepthExceptions, but whose message will never be used. Another related reason is to remove the need to create a different exception before creating this one just for the purpose of searching through its stack trace for the proper stack depth. Still one more reason is to allow the message to contain information about the stack depth, such as the failed file name and line number.

Attributes

Inherited from:
StackDepthException
val position: Option[Position]

An optional source position describing the line of test code that caused this exception.

An optional source position describing the line of test code that caused this exception.

Attributes

Inherited from:
StackDepthException