Executes the supplied code (a by-name parameter) and returns in an optional throwable indicating whether the passed expression failed (threw an exception that would normally cause a test to fail) or succeeded (did not throw any exception).
Executes the supplied code (a by-name parameter) and returns in an optional throwable indicating whether the passed expression failed (threw an exception that would normally cause a test to fail) or succeeded (did not throw any exception).
Because Error
s are used to denote serious errors, trait Suite
and its subtypes in the
ScalaTest API do not always treat a test that completes abruptly with an Error
as a test failure, but sometimes as
an indication that serious problems have arisen that should cause the run to abort. For example, if a test completes abruptly
with an OutOfMemoryError
, it will not be reported as a test failure, but will instead cause the run to abort.
Because not everyone uses Error
s only to represent serious problems, however, ScalaTest only behaves this way
for the following exception types (and their subclasses):
java.lang.annotation.AnnotationFormatError
java.awt.AWTError
java.nio.charset.CoderMalfunctionError
javax.xml.parsers.FactoryConfigurationError
java.lang.LinkageError
java.lang.ThreadDeath
javax.xml.transform.TransformerFactoryConfigurationError
java.lang.VirtualMachineError
The previous list includes all Error
s that exist as part of Java 1.5 API, excluding java.lang.AssertionError
. ScalaTest
does treat a thrown AssertionError
as an indication of a test failure. In addition, any other Error
that is not an instance of a
type mentioned in the previous list will be caught by the Suite
traits in the ScalaTest API and reported as the cause of a test failure.
If the code supplied to failureOf
completes abruptly in one of the errors in the previous list, failureOf
will not return it wrapped in an option, but rather will complete abruptly with the same exception. The failureOf
method
will wrap any other exception thrown by the supplied code in a Some
and return it.
Companion object that facilitates the importing of
FailureOf
's method as an alternative to mixing it in. One use case is to importFailureOf
's method so you can use it in the Scala interpreter: