sealed trait Status extends AnyRef
The result status of running a test or a suite, which is used to support parallel and asynchronous execution of tests.
This trait is the result type of the "run" lifecycle methods of trait Suite
:
run
, runNestedSuites
, runTests
, and runTest
. It can be used to determine whether
a test or suite has completed, and if so, whether it succeeded, and if not, whether an exception was thrown that was
not yet reported via a ScalaTest event. A Status
is like a domain-specific Future[Boolean]
, where:
- an activity in which no test failed and no suite aborted is represented by
Success(true)
- an activity during which at least one test failed or one suite aborted, but all exceptions that occured
were reported by a ScalaTest events (such as
TestFailedException
) is represented bySuccess(false)
- an activity during which at least one test failed or one suite aborted and at least one exception occurred that was
not reported via a ScalaTest event is represented by
Failure(unreportedException)
Note that pending and canceled tests will not cause a Status
to fail. Only failed tests
and aborted suites will cause a Status
to fail.
One use case of Status
is to ensure that "after" code (such as an afterEach
or afterAll
method)
does not execute until after the relevant entity (one test, one suite, or all of a suite's tests or nested suites) has completed.
Another use case is to implement the default behavior of asynchronous styles, in which subsequent each test does not begin
execution until after the previous test has completed.
- Self Type
- Status
- Source
- Status.scala
- Alphabetic
- By Inheritance
- Status
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
isCompleted: Boolean
Non-blocking call that indicates whether the entity represented by this
Status
(one test, one suite, or all of a suite's tests or nested suites) has completed.Non-blocking call that indicates whether the entity represented by this
Status
(one test, one suite, or all of a suite's tests or nested suites) has completed. Because this is non-blocking, you can use this to poll the completion status.Note: this method will not indicate whether a test has failed, suite has aborted, or an unreported exception has been installed. It just indicates whether the
Status
has completed or not by returningtrue
orfalse
.- returns
true
if the test or suite run is already completed,false
otherwise.
-
abstract
def
succeeds(): Boolean
Blocking call that waits until the entity represented by this
Status
(one test, one suite, or all of a suite's tests or nested suites) has completed, then returnstrue
if no tests failed and no suites aborted, else returnsfalse
, or if an unreported exception has been installed, completes abruptly with that exception.Blocking call that waits until the entity represented by this
Status
(one test, one suite, or all of a suite's tests or nested suites) has completed, then returnstrue
if no tests failed and no suites aborted, else returnsfalse
, or if an unreported exception has been installed, completes abruptly with that exception.This method only reports
false
if there was a failed test or aborted suite in the context of the "run" lifecycle method from which it was returned. For example, if you callsucceeds
on aStatus
returned byrunTest
,succeeds
will (after that test has completed) returnfalse
if the test whose name was passed torunTest
fails, else it will returntrue
. In other words, so long as the test doesn't fail —whether the test succeeds, is canceled, or is pending—succeeds
will returntrue
. If you callsucceeds
on aStatus
returned byrunTests
, by contrast,succeeds
will (after the suite's tests have completed) returntrue
only if none of the tests in the suite fail. If any test in the suite fails,succeeds
will returnfalse
. If you callsucceeds
on aStatus
returned byrunNestedSuites
,succeeds
will return true only if no tests fail and no suites abort when running all nested suites (and their nested suites, recursively). Similarly, if you callsucceeds
on aStatus
returned byrun
,succeeds
will return true only if no tests fail and no suites abort when running all tests nested suites (and their nested suites, recursively).If this
Status
fails with an "unreported exception," an exception that occurred during the activity represented by thisStatus
that was not reported to theReporter
via a ScalaTest event, thesucceeds
method will complete abruptly with that exception. If the original exception was a run-aborting exception, such asStackOverflowError
, theunreportedException
method will return ajava.util.ExecutionException
that contains the original run-aborting exception as its cause. Thesucceeds
method will in that case complete abruptly with theExecutionException
that wraps the original run-aborting exception.Note: because blocking is not possible on Scala.js, this method is not available on Scala.js.
- returns
after waiting until completion,
true
if no tests failed and no suites aborted,false
otherwise
- Exceptions thrown
unreportedException
if an exception occurred during the activity represented by thisStatus
that was not reported via a ScalaTest event and therefore was installed as an unreported exception on thisStatus
.
-
abstract
def
waitUntilCompleted(): Unit
Blocking call that waits until the entity represented by this
Status
(one test, one suite, or all of a suite's tests or nested suites) has completed, then either returns normally, or if an unreported exception has been installed, completes abruptly with that unreported exception.Blocking call that waits until the entity represented by this
Status
(one test, one suite, or all of a suite's tests or nested suites) has completed, then either returns normally, or if an unreported exception has been installed, completes abruptly with that unreported exception.If this
Status
fails with an "unreported exception," an exception that occurred during the activity represented by thisStatus
that was not reported to theReporter
via a ScalaTest event, thewaitUntilCompleted
method will complete abruptly with that exception. If the original exception was a run-aborting exception, such asStackOverflowError
, theunreportedException
method will return ajava.util.ExecutionException
that contains the original run-aborting exception as its cause. ThewaitUntilCompleted
method will in that case complete abruptly with theExecutionException
that wraps the original run-aborting exception.Note: because blocking is not possible on Scala.js, this method is not available on Scala.js.
- Exceptions thrown
unreportedException
if an exception occurred during the activity represented by thisStatus
that was not reported via a ScalaTest event and therefore was installed as an unreported exception on thisStatus
.
-
abstract
def
whenCompleted(callback: (Try[Boolean]) ⇒ Unit): Unit
Registers the passed callback function to be executed when this status completes.
Registers the passed callback function to be executed when this status completes.
If an unreported exception has been installed on this
Status
, theTry
passed into the callback function will be aFailure
containing that exception. Otherwise theTry
will be aSuccess
containing true if no tests failed or suites aborted during the activity represented by thisStatus
, elsefalse
.The callback functions registered with
whenCompleted
will be executed after theStatus
has completed, in an undefined order. If theStatus
has already completed, functions passed to this method will be executed immediately by the calling thread before returning.Any exception thrown by a callback function will be propagated back on the thread used to invoke the callback.
Internally ScalaTest uses this method to register callbacks that fire completion events (
TestSucceeded
,TestFailed
,SuiteCompleted
, etc.) to theReporter
.- callback
the callback function to execute once this
Status
has completed
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
final
def
thenRun(f: ⇒ Status): Status
Registers a
Status
-producing by-name function to execute after thisStatus
completes, returning aStatus
that mirrors theStatus
returned by the by-name.Registers a
Status
-producing by-name function to execute after thisStatus
completes, returning aStatus
that mirrors theStatus
returned by the by-name.The
Status
returned by this method will complete when the status produced by theStatus
produced by the passed-by name completes. The returnedStatus
will complete with the samesucceeds
andunreportedException
values. But unlike theStatus
produced by the by-name, the returnedStatus
will be available immediately.If the by-name function passed to this method completes abruptly with a non-run-aborting exception, that exception will be caught and installed as the
unreportedException
on theStatus
returned by this method. TheStatus
returned by this method will then complete. The thread that attempted to evaluate the by-name function will be allowed to continue (i.e.
, the non-run-aborting exception will not be rethrown on that thread).If the by-name function passed to this method completes abruptly with a run-aborting exception, such as
StackOverflowError
, that exception will be caught and a newjava.util.concurrent.ExecutionException
that contains the run-aborting exception as its cause will be installed as theunreportedException
on theStatus
returned by this method. TheStatus
returned by this method will then complete. The original run-aborting exception will then be rethrown on the thread that attempted to evaluate the by-name function.If an unreported exception is installed on this
Status
, the passed by-name function will not be executed. Instead, the same unreported exception will be installed on theStatus
returned by this method.Internally, ScalaTest uses this method in async styles to ensure that by default, each subsequent test in an async-style suite begins execution only after the previous test has completed. This method is not used if
ParallelTestExection
is mixed into an async style. Instead, tests are allowed to begin execution concurrently.- returns
a
Status
that represents the status of executing the by-name function passed to this method.
-
final
def
toFuture: Future[Boolean]
Converts this
Status
to aFuture[Boolean]
whereSuccess(true)
means no tests failed and suites aborted,Success(false)
, means at least one test failed or one suite aborted and any thrown exception was was reported to theReporter
via a ScalaTest event,Failure(unreportedException)
means an exception,unreportedException
, was thrown that was not reported to theReporter
via a ScalaTest event.Converts this
Status
to aFuture[Boolean]
whereSuccess(true)
means no tests failed and suites aborted,Success(false)
, means at least one test failed or one suite aborted and any thrown exception was was reported to theReporter
via a ScalaTest event,Failure(unreportedException)
means an exception,unreportedException
, was thrown that was not reported to theReporter
via a ScalaTest event.- returns
a
Future[Boolean]
representing thisStatus
.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
unreportedException: Option[Throwable]
An exception that was thrown during the activity represented by this
Status
that was not reported via a ScalaTest event fired to theReporter
.An exception that was thrown during the activity represented by this
Status
that was not reported via a ScalaTest event fired to theReporter
.When a test executes, "non-run-aborting" thrown exceptions are reported by events fired to the reporter. A
TestPendingException
is reported via aTestPending
event. ATestCanceledException
is reported via aTestCanceled
event. Any other non-run-aborting exceptions, includingTestFailedException
will be reported via aTestFailed
event.Run-aborting exceptions indicate critical problems, such as
OutOfMemoryError
, that instead of being reported via a test completion event should instead cause the entire suite to abort. In synchronous testing styles, this exception will be allowed to just propagate up the call stack. But in async styles, the thread or threads executing the test will often be taken from the async suite's execution context. Instead of propagating these run-aborting exceptions up the call stack, they will be installed as an "unreported exception" in the test'sStatus
. They are "unreported" because no test completion event will be fired to report them. For more explanation and a list of run-aborting exception types, see Treatment ofjava.lang.Error
s.Another way for an unreported exception to occur is if an exception of any type is thrown outside of the body of an actual test. For example, traits
BeforeAndAfter
,BeforeAndAfterEach
, andBeforeAndAfterEachTestData
execute code before and after tests. TraitsBeforeAndAfterAll
andBeforeAndAfterAllConfigMap
execute code before and after all tests and nested suites of a suite. If any "before" or "after" code completes abruptly with an exception (of any type, not just run-aborting types) on a thread taken from an async suite's execution context, this exception will installed as anunreportedException
of the relevantStatus
.In addition, ScalaTest
Suite
exposes four "run" lifecycle methods--run
,runNestedSuites
,runTests
, andrunTest
--that users can override to customize the framework. If a "run" lifecycle methods completes abruptly with an exception, that exception occurs outside the context of a test body. As a result, such exceptions will be installed as anunreportedException
of the relevantStatus
.The
toFuture
method onStatus
returns aFuture[Boolean]
. If theFuture
succeeds with theBoolean
value oftrue
, that indicates no tests failed and no suites aborted during the activity represented by thisStatus
. If a test failed or suite aborted, and that event was reported by a fired ScalaTestEvent
, theFuture
will succeed with the valuefalse
. If an unreported exception has been installed on theStatus
, however, theFuture
will fail with that exception.- returns
a optional unreported
Throwable
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
withAfterEffect(f: ⇒ Unit): Status
Registers a by-name function (producing an optional exception) to execute after this
Status
completes.Registers a by-name function (producing an optional exception) to execute after this
Status
completes.If the by-name function passed to this method completes abruptly with a non-run-aborting exception, that exception will be caught and installed as the
unreportedException
on theStatus
returned by this method. TheStatus
returned by this method will then complete. The thread that attempted to evaluate the by-name function will be allowed to continue (i.e.
, the non-run-aborting exception will not be rethrown on that thread).If the by-name function passed to this method completes abruptly with a run-aborting exception, such as
StackOverflowError
, that exception will be caught and a newjava.util.concurrent.ExecutionException
that contains the run-aborting exception as its cause will be installed as theunreportedException
on theStatus
returned by this method. TheStatus
returned by this method will then complete. The original run-aborting exception will then be rethrown on the thread that attempted to evaluate the by-name function.If an unreported exception is installed on this
Status
, the passed by-name function will not be executed. Instead, the same unreported exception will be installed on theStatus
returned by this method.Internally, ScalaTest uses this method in traits
BeforeAndAfter
,BeforeAndAfterEach
, andBeforeAndAfterEachTestData
to ensure "after" code is executed after the relevant test has completed, and in traitsBeforeAndAfterAll
andBeforeAndAfterAllConfigMap
to ensure "after" code is executed after the relevant tests and nested suites have completed.- f
A by-name function to invoke after this
Status
has completed.- returns
a
Status
that represents thisStatus
, modified by any exception thrown by the passed by-name function.