A global extension ArquillianSpockExtension (of type org.spockframework.runtime.extension.IGlobalExtension) is used to hook into the Spock/Sputnik testrunner lifecycle.
This allows an @Deployment method specified in a Specification to be found (indirectly) by the Sputnik testrunner:
- The
ArquillianSpockExtensionbuilds a new instance of an ArquillianTestRunnerAdaptor. This adaptor is used to manage the Arquillian lifecycle. - An
ArquillianInterceptor(that references the previously createdTestRunnerAdaptor) is established as an interceptor for severalSpecmethod kinds: SETUP_SPEC, CLEANUP_SPEC, SETUP, CLEANUP and FEATURE. - When the Sputnik testrunner fires a method of type SETUP_SPEC, the
ArquillianInterceptorintercepts this invocation to direct theTestRunnerAdaptorof Arquillian to fires it'sBeforeClassevent. At this point, managed/embedded containers would be started by Arquillian. A deployment scenario is generated if a@Deploymentmethod is detected, and the created (and enriched) archive is deployed. - When the Sputnik testrunner fires a method of type FEATURE, the
ClientTestExecutorof Arquillian (that observes theTestevent) fires aRemoteExecutionEventthat triggers theRemoteTestExecuterof Arquillian to send a request to execute the desired method on the container. In the container, theServletTestRunner(present due to the Servlet protocol), delegates the execution of the test method to theSpockTestRunnerclass (that is deployed along with theSpecificationclasses) on the container.
In the JBehave integration the Arquillian testrunner performs all the necessary activities of:
- starting containers,
- handling
@Deploymentmethods, - running the tests (both in-client and in-container),
- and delegating the actual execution to the
Embedder/Embeddableinstance.
In the Spock integration, the Sputnik testrunner relies on the Arquillian-Spock extension hooking onto the test lifecycle of a Specification. Once the necessary hooks have been established, Arquillian intercepts the events on the client (and establishes a communication channel with the server) to execute the methods in-container, apart from performing the necessary activities.
We'll need features within the Thucydides API to intercept the various events in a Thucydides test lifecycle. For instance, we'll need to intercept the BeforeClass/BeforeFeature event (or the equivalent event in Thucydides), to start the Arquillian TestRunnerAdaptor, to eventually start the containers and deploy the tests. Also, such events should contain information about the actual Test instance so that the @Deployment method can be located by Arquillian.
For now, the Thucydides-Arquillian example uses the StepListener interface of Thucydides to hook into the suite start and end events, with each suite composed of a single test class or (easyb) story. ThreadLocals are used to store state within the StepListener, primarily since the testSuiteFinished event does not provide information about the Class or Story whose suite has finished.