public interface TestListenerRule extends TestRule
The purpose is here to provide an interface that can be implemented by rule implementor to do action, before, after and on some condition.
Rule implementer should implements this interface and then implement the required methods (which are do-nothing method by default). The order of execution is the following :
onStart(TestContext)
is executed.onFailure(TestContext, AssertionError)
in case of test failure.onError(TestContext, Throwable)
in case of test error.onAssumptionSkip(TestContext, AssumptionError)
in case of test
skip.onEnd(TestContext)
is executed.ExternalResource
rule implements this interface to provide simple
use case (action before and always after test).ExternalResource
Modifier and Type | Method and Description |
---|---|
default Statement<TestContext<Object>,Throwable> |
computeStatement(Statement<TestContext<Object>,Throwable> inner)
The default implementation of test rule.
|
static TestListenerRule |
of(Consumer<TestContext<Object>> onStart,
Consumer<TestContext<Object>> onEnd,
BiConsumer<TestContext<Object>,AssertionError> onFailure,
BiConsumer<TestContext<Object>,Throwable> onError,
BiConsumer<TestContext<Object>,AssumptionError> onAssumptionSkip)
Build a
TestListenerRule based on the various method. |
default void |
onAssumptionSkip(TestContext<Object> context,
AssumptionError error)
Method used when an assumption error happened.
|
static TestListenerRule |
onEnd(Consumer<TestContext<Object>> onEnd)
Build a
TestListenerRule with only an action at end. |
default void |
onEnd(TestContext<Object> context)
Method used at the end of the test.
|
default void |
onError(TestContext<Object> context,
Throwable error)
Method used when an error happened.
|
default void |
onFailure(TestContext<Object> context,
AssertionError af)
Method used when a failure happened.
|
static TestListenerRule |
onStart(Consumer<TestContext<Object>> onStart)
Build a
TestListenerRule with only an action at start. |
default void |
onStart(TestContext<Object> context)
Method used at the start of the test.
|
default void onStart(TestContext<Object> context)
Default implementation is to do nothing.
context
- the test contextdefault void onFailure(TestContext<Object> context, AssertionError af)
Default implementation is to do nothing.
context
- the test contextaf
- the failuredefault void onError(TestContext<Object> context, Throwable error)
Default implementation is to do nothing.
context
- the test contexterror
- the errordefault void onAssumptionSkip(TestContext<Object> context, AssumptionError error)
Default implementation is to do nothing.
context
- the test contexterror
- the assumption errordefault void onEnd(TestContext<Object> context)
Default implementation is to do nothing.
context
- the test contextdefault Statement<TestContext<Object>,Throwable> computeStatement(Statement<TestContext<Object>,Throwable> inner)
TestRule
The goal of this method is to compute another test statement that will be the one to be runned.
computeStatement
in interface TestRule
inner
- the inner statementstatic TestListenerRule of(Consumer<TestContext<Object>> onStart, Consumer<TestContext<Object>> onEnd, BiConsumer<TestContext<Object>,AssertionError> onFailure, BiConsumer<TestContext<Object>,Throwable> onError, BiConsumer<TestContext<Object>,AssumptionError> onAssumptionSkip)
TestListenerRule
based on the various method.onStart
- the action to be done before the
test start
. If null, nothing is done.onEnd
- the action to be done after the
test end
. If null, nothing is done.onFailure
- the action to
be done in case of failure
. If null, nothing is done.onError
- the action to be done
in case of error
. If null, nothing is done.onAssumptionSkip
- the
action to be done in case of assumption skipped
. If null
nothing is done.static TestListenerRule onStart(Consumer<TestContext<Object>> onStart)
TestListenerRule
with only an action at start.onStart
- the action to be done before the
test start
.static TestListenerRule onEnd(Consumer<TestContext<Object>> onEnd)
TestListenerRule
with only an action at end.onEnd
- the action to be done after the
test end
.Copyright © 2015 Powerunit. All rights reserved.