Skip to main content
Version: 5.5

Simple Extensions

This table lists the most basic extensions, that cover test and spec lifecycle events, and are mostly equivalent to lifecycle hooks. For more advanced extensions that can be used to modify the way the Engine runs, see advanced extensions.

ExtensionDescription
BeforeContainerListenerInvoked directly before each test with type TestType.Container is executed. If the test is marked as ignored / disabled / inactive, then this callback won't be invoked.
AfterContainerListenerInvoked immediately after a TestCase with type TestType.Container has finished. If a test case was skipped (ignored / disabled / inactive) then this callback will not be invoked for that particular test case.

The callback will execute even if the test fails.
BeforeEachListenerInvoked directly before each test with type TestType.Test is executed. If the test is marked as ignored / disabled / inactive, then this callback won't be invoked.
AfterEachListenerInvoked immediately after a TestCase with type TestType.Test has finished, with the TestResult of that test. If a test case was skipped (ignored / disabled / inactive) then this callback will not be invoked for that particular test case.

The callback will execute even if the test fails.
BeforeTestListenerInvoked directly before each test is executed with the TestCase instance as a parameter. If the test is marked as ignored / disabled / inactive, then this callback won't be invoked.
AfterTestListenerInvoked immediately after a TestCase has finished with the TestResult of that test. If a test case was skipped (ignored / disabled / inactive) then this callback will not be invoked for that particular test case.

The callback will execute even if the test fails.
BeforeInvocationListenerInvoked before each 'run' of a test, with a flag indicating the iteration number. If you are running a test with the default single invocation then this callback is effectively the same as beforeTest.

Note: If you have multiple invocations and multiple threads, then this callback will be invoked concurrently.
AfterInvocationListenerInvoked after each 'run' of a test, with a flag indicating the iteration number. If you are running a test with the default single invocation then this callback is effectively the same as afterTest.

Note: If you have multiple invocations and multiple threads, then this callback will be invoked concurrently.
BeforeSpecListenerInvoked after the Engine instantiates a spec to be used as part of a test execution. If a spec is instantiated multiple times - for example, if InstancePerTest or InstancePerLeaf isolation modes are used, then this callback will be invoked for each instance created.

This callback can be used to perform setup each time a new spec instance is created. To perform setup once per class, then use PrepareSpecListener.

This listener is invoked before any test lifecycle events.
AfterSpecListenerIs invoked after the TestCases that are part of a particular spec instance have completed.

If a spec is instantiated multiple times - for example, if InstancePerTest or InstancePerLeaf isolation modes are used, then this callback will be invoked for each instantiated spec, after the tests that are applicable to that spec instance have returned.

This callback can be used to perform cleanup after each individual spec instance. To perform cleanup once per class, then use FinalizeSpecListener.

This listener is invoked after all test lifecycle events.
PrepareSpecListenerCalled once per spec, when the engine is preparing to execute the tests for that spec.

Regardless of how many times the spec is instantiated, for example, if InstancePerTest or InstancePerLeaf isolation modes are used, this callback will only be invoked once. If the spec is skipped then this callback will not be invoked.
FinalizeSpecListenerCalled once per Spec, after all tests have completed for that spec.

Regardless of how many times the spec is instantiated, for example, if InstancePerTest or InstancePerLeaf isolation modes are used, this callback will only be invoked once. If the spec is skipped then this callback will not be invoked.
BeforeProjectListenerIs invoked before any specs are created.
AfterProjectListenerIs invoked once all tests and specs have completed