org.scalatest.exceptions
Classes and traits for exceptions thrown by ScalaTest.
This package is released as part of the scalatest-core
module.
Attributes
Members list
Type members
Classlikes
Exception that indicates an evaluation of a property should be discarded, because a condition required by a property was not met by the passed values.
Exception that indicates an evaluation of a property should be discarded, because a condition required by a property was not met by the passed values.
This exception is thrown by the whenever
method defined in trait Whenever
when the given condition is false. The forAll
methods defined in trait PropertyChecks
catch the DiscardedEvaluationException
and ignore it, moving on to try the next set of parameter values it is checking th property against.
Attributes
- Supertypes
-
class RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Exception that indicates an attempt was made to register a test that had the same name as a test already registered in the same suite. The purpose of this exception is to encapsulate information about the stack depth at which the line of code that made this attempt resides, so that information can be presented to the user that makes it quick to find the problem line of code. (In other words, the user need not scan through the stack trace to find the correct filename and line number of the offending code.)
Exception that indicates an attempt was made to register a test that had the same name as a test already registered in the same suite. The purpose of this exception is to encapsulate information about the stack depth at which the line of code that made this attempt resides, so that information can be presented to the user that makes it quick to find the problem line of code. (In other words, the user need not scan through the stack trace to find the correct filename and line number of the offending code.)
Value parameters
- posOrStackDepthFun
-
either a source position or a function that return the depth in the stack trace of this exception at which the line of code that attempted to register the test with the duplicate name resides.
- testName
-
the test name that was attempted to be registered twice
Attributes
- Throws
-
NullArgumentException
if
testName
isnull
- Supertypes
-
class StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Exception that indicates a ScalaCheck property check failed.
Exception that indicates a ScalaCheck property check failed.
Value parameters
- args
-
the argument values, if any, that caused the property check to fail.
- cause
-
an optional cause, the
Throwable
that caused thisGeneratorDrivenPropertyCheckFailedException
to be thrown. - labels
-
the labels, if any (see the ScalaCheck user guide for information on labels)
- messageFun
-
a function that returns a detail message (not optional) for this
GeneratorDrivenPropertyCheckFailedException
. - namesOfArgs
-
an optional list of string names for the arguments.
- payload
-
an optional payload, which ScalaTest will include in a resulting
TestFailed
event - posOrStackDepthFun
-
either a source position or a function that returns the depth in the stack trace of this exception at which the line of test code that failed resides.
- undecoratedMessage
-
just a short message that has no redundancy with args, labels, etc. The regular "message" has everything in it.
Attributes
- Throws
-
NullArgumentException
if any parameter is
null
orSome(null)
. - Supertypes
-
class TestFailedExceptiontrait PayloadFieldclass StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Trait implemented by exception types that can modify their detail message.
Trait implemented by exception types that can modify their detail message.
This trait facilitates the withClue
construct provided by trait Assertions
. This construct enables extra information (or "clues") to be included in the detail message of a thrown exception. Although both assert
and expect
provide a way for a clue to be included directly, assertThrows
, intercept
, and ScalaTest matcher expressions do not. Here's an example of clues provided directly in assert
:
assert(1 + 1 === 3, "this is a clue")
and in expect
:
expect(3, "this is a clue") { 1 + 1 }
The exceptions thrown by the previous two statements will include the clue string, "this is a clue"
, in the exceptions detail message. To get the same clue in the detail message of an exception thrown by a failed assertThrows
call requires using withClue
:
withClue("this is a clue") { assertThrows[IndexOutOfBoundsException] { "hi".charAt(-1) } }
Similarly, to get a clue in the exception resulting from an exception arising out of a ScalaTest matcher expression, you need to use withClue
. Here's an example:
withClue("this is a clue") { 1 + 1 should === (3) }
Exception types that mix in this trait have a modifyMessage
method, which returns an exception identical to itself, except with the detail message option replaced with the result of invoking the passed function, supplying the current detail message option as the lone String
parameter.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
- Self type
-
Throwable
Trait implemented by PayloadField
exception types that can modify their payload.
Trait implemented by PayloadField
exception types that can modify their payload.
This trait facilitates the withPayload
construct provided by trait Payloads
. This construct enables a payload object (or modified payload object) to be included as the payload of a thrown exception. The payload can then be included in the ScalaTest event that results from that exception. For example, the payload included in a TestFailedException
will be included as the payload of the resulting TestFailed
event. Here's an example in which a GUI snapshot is included as a payload when a test fails:
withPayload(generateGUISnapshot()) { 1 + 1 should === (3) }
Exception types that mix in this trait have a modifyPayload
method, which returns an exception identical to itself, except with the payload option replaced with the result of invoking the passed function, supplying the current payload option as the lone Option[Any]
parameter.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
- Self type
-
Exception that indicates something was attempted in test code that is not allowed. For example, in a FeatureSpec
, it is not allowed to nest a feature
clause inside another feature
clause. If this is attempted, the construction of that suite will fail with a NotAllowedException
.
Exception that indicates something was attempted in test code that is not allowed. For example, in a FeatureSpec
, it is not allowed to nest a feature
clause inside another feature
clause. If this is attempted, the construction of that suite will fail with a NotAllowedException
.
Value parameters
- cause
-
an optional cause
- message
-
a string that explains the problem
- posOrStackDepthFun
-
either a source position or a function that return the depth in the stack trace of this exception at which the line of code that attempted something not allowed resides.
Attributes
- Throws
-
NullArgumentException
if either
message
orfailedCodeStackDepthFun
isnull
- Supertypes
-
class StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Wrapper exception that wraps an non-serializable exception encountered in Event
.
Wrapper exception that wraps an non-serializable exception encountered in Event
.
Value parameters
- exceptionClassName
-
the class name of the exception being wrapped
- exceptionStackTrace
-
the stack trace of the exception being wrapped
- msg
-
a string that explains the problem
Attributes
- Throws
-
NullArgumentException
if either
message
orfailedCodeStackDepthFun
isnull
- Supertypes
-
trait Producttrait Equalsclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Trait implemented by exception types that carry an optional payload.
Trait implemented by exception types that carry an optional payload.
Many ScalaTest events include an optional "payload" field that can be used to pass information to a custom reporter. This trait facilitates such customization, by allowing test code to include a payload in an exception (such as TestFailedException
). ScalaTest looks for this trait and fires any payloads it finds in the relevant ScalaTest event stimulated by the exception, such as a TestFailed
event stimulated by a TestFailedException
. (Although in its initial release there is only two subclasses of PayloadField
in ScalaTest, TestFailedException
and TestCanceledException
, in future version of ScalaTest, there could be more)
For an example of how payloads could be used, see the documentation for trait Payloads
.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
- Self type
-
Throwable
Exception that indicates a property check failed.
Exception that indicates a property check failed.
Value parameters
- args
-
the argument values that caused the property check to fail.
- cause
-
an optional cause, the
Throwable
that caused thisPropertyCheckFailedException
to be thrown. - messageFun
-
a function that returns a detail message (not optional) for this
PropertyCheckFailedException
. - optionalArgNames
-
an optional list of string names for the arguments.
- payload
-
an optional payload, which ScalaTest will include in a resulting
TestFailed
event - posOrStackDepthFun
-
either a source position or a function that returns the depth in the stack trace of this exception at which the line of test code that failed resides.
- undecoratedMessage
-
just a short message that has no redundancy with args, labels, etc. The regular "message" has everything in it.
Attributes
- Throws
-
NullArgumentException
if any parameter is
null
orSome(null)
. - Supertypes
-
class TestFailedExceptiontrait PayloadFieldclass StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
- Known subtypes
Trait that encapsulates the information required of an exception thrown by ScalaTest's assertions and matchers, which includes a stack depth at which the failing line of test code resides.
Trait that encapsulates the information required of an exception thrown by ScalaTest's assertions and matchers, which includes a stack depth at which the failing line of test code resides.
This trait exists so that it can be mixed into two exception superclasses, StackDepthException
, from which extend several exceptions that do not depend on JUnit, and JUnitTestFailedError
, which does depend on JUnit. The latter, which requires JUnit be in the classpath, ensures failed ScalaTest assertions are reported as "failures," not "errors," by JUnit.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class StackDepthExceptionclass NotAllowedExceptionclass TestCanceledExceptionclass TestFailedExceptionShow all
- Self type
-
Throwable
Exception class that encapsulates information about the stack depth at which the line of code that failed resides, so that information can be presented to the user that makes it quick to find the failing line of code. (In other words, the user need not scan through the stack trace to find the correct filename and line number of the problem code.) Having a stack depth is more useful in a testing environment in which test failures are implemented as thrown exceptions, as is the case in ScalaTest's built-in suite traits.
Exception class that encapsulates information about the stack depth at which the line of code that failed resides, so that information can be presented to the user that makes it quick to find the failing line of code. (In other words, the user need not scan through the stack trace to find the correct filename and line number of the problem code.) Having a stack depth is more useful in a testing environment in which test failures are implemented as thrown exceptions, as is the case in ScalaTest's built-in suite traits.
Value parameters
- cause
-
an optional cause, the
Throwable
that caused thisStackDepthException
to be thrown. - messageFun
-
a function that produces an optional detail message for this
StackDepthException
. - posOrStackDepthFun
-
either 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
orfailedCodeStackDepthFun
isnull
, orSome(null)
. - Supertypes
-
trait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
- Known subtypes
Exception that indicates a table-driven property check failed.
Exception that indicates a table-driven property check failed.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
Value parameters
- args
-
the argument values
- cause
-
an optional cause, the
Throwable
that caused thisTableDrivenPropertyCheckFailedException
to be thrown. - messageFun
-
a function that returns a detail message, not optional) for this
TableDrivenPropertyCheckFailedException
. - namesOfArgs
-
a list of string names for the arguments
- payload
-
an optional payload, which ScalaTest will include in a resulting
TestFailed
event - posOrStackDepthFun
-
either a source position or a function that returns the depth in the stack trace of this exception at which the line of test code that failed resides.
- row
-
the index of the table row that failed the property check, causing this exception to be thrown
- undecoratedMessage
-
just a short message that has no redundancy with args, labels, etc. The regular "message" has everything in it
Attributes
- Throws
-
NullArgumentException
if any parameter is
null
orSome(null)
. - Supertypes
-
class TestFailedExceptiontrait PayloadFieldclass StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Exception thrown to indicate a test has been canceled.
Exception thrown to indicate a test has been canceled.
A canceled test is one that is unable to run because a needed dependency, such as an external database, is missing.
Canceled tests are ones that complete abruptly with a TestCanceledException
after starting.
Value parameters
- cause
-
an optional cause, the
Throwable
that caused thisTestCanceledException
to be thrown. - messageFun
-
a function that return an optional detail message for this
TestCanceledException
. - payload
-
an optional payload, which ScalaTest will include in a resulting
TestCanceled
event - posOrStackDepthFun
-
either a source position or a function that return the depth in the stack trace of this exception at which the line of test code that failed resides.
Attributes
- Supertypes
-
trait PayloadFieldclass StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Subclass of TestFailedException
representing tests that failed because of a timeout.
Subclass of TestFailedException
representing tests that failed because of a timeout.
This exception is thrown by the failAfter
method of trait Timeouts
, the eventually
method of trait Eventually
, and the await
methods of trait AsyncAssertions
.
Value parameters
- cause
-
an optional cause, the
Throwable
that caused thisTestFailedDueToTimeoutException
to be thrown. - messageFun
-
a function that produces an optional detail message for this
TestFailedDueToTimeoutException
. - posOrStackDepthFun
-
either 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.
- timeout
-
the timeout that expired
Attributes
- Throws
-
NullArgumentException
if either
messageFun
,cause
orfailedCodeStackDepthFun
isnull
, orSome(null)
. - Supertypes
-
trait TimeoutFieldclass TestFailedExceptiontrait PayloadFieldclass StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Exception that indicates a test failed.
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 thisTestFailedException
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
orfailedCodeStackDepthFun
isnull
, orSome(null)
. - Supertypes
-
trait PayloadFieldclass StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
- Known subtypes
Exception thrown to indicate a test is pending.
Exception thrown to indicate a test is pending.
A pending test is one that has been given a name but is not yet implemented. The purpose of pending tests is to facilitate a style of testing in which documentation of behavior is sketched out before tests are written to verify that behavior (and often, the before the behavior of the system being tested is itself implemented). Such sketches form a kind of specification of what tests and functionality to implement later.
To support this style of testing, a test can be given a name that specifies one bit of behavior required by the system being tested. The test can also include some code that sends more information about the behavior to the reporter when the tests run. At the end of the test, it can call method pending
, which will cause it to complete abruptly with TestPendingException
. Because tests in ScalaTest can be designated as pending with TestPendingException
, both the test name and any information sent to the reporter when running the test can appear in the report of a test run. (In other words, the code of a pending test is executed just like any other test.) However, because the test completes abruptly with TestPendingException
, the test will be reported as pending, to indicate the actual test, and possibly the functionality, has not yet been implemented.
Attributes
- Supertypes
-
class RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Exception that indicates an action that is only allowed during a suite's test registration phase, such as registering a test to run or ignore, was attempted after registration had already closed.
Exception that indicates an action that is only allowed during a suite's test registration phase, such as registering a test to run or ignore, was attempted after registration had already closed.
In suites that register tests as functions, such as FunSuite
and FunSpec
, tests are normally registered during construction. Although it is not the usual approach, tests can also be registered after construction by invoking methods that register tests on the already constructed suite so long as run
has not been invoked on that suite. As soon as run
is invoked for the first time, registration of tests is "closed," meaning that any further attempts to register a test will fail (and result in an instance of this exception class being thrown). This can happen, for example, if an attempt is made to nest tests, such as in a FunSuite
:
test("this test is fine") { test("but this nested test is not allowed") { } }
This exception encapsulates information about the stack depth at which the line of code that made this attempt resides, so that information can be presented to the user that makes it quick to find the problem line of code. (In other words, the user need not scan through the stack trace to find the correct filename and line number of the offending code.)
Value parameters
- message
-
the exception's detail message
- posOrStackDepthFun
-
either a source position or a function that return the depth in the stack trace of this exception at which the line of code that attempted to register the test after registration had been closed.
Attributes
- Throws
-
NullArgumentException
if either
message
orfailedCodeStackDepthFun
isnull
- Supertypes
-
class StackDepthExceptiontrait StackDepthclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Trait mixed into exceptions thrown due to a timeout, which offers a timeout
field providing a Span
representing the timeout that expired.
Trait mixed into exceptions thrown due to a timeout, which offers a timeout
field providing a Span
representing the timeout that expired.
This trait is used by trait TimeLimitedTests
to detect exceptions thrown because of timeouts, and for such exceptions, to modify the message to more clearly indicate a test timed out. (Although in its initial release there is only one subclass of TimeoutField
in ScalaTest, TestFailedDueToTimeoutException
, in future version of ScalaTest, there could be more)
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
- Self type
-
Throwable