Skip to content

Instantly share code, notes, and snippets.

@VineetReynolds
Created February 24, 2012 11:08
Show Gist options
  • Save VineetReynolds/1900187 to your computer and use it in GitHub Desktop.
Save VineetReynolds/1900187 to your computer and use it in GitHub Desktop.
Arquillian Spock Integration Notes

Design Notes

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 ArquillianSpockExtension builds a new instance of an Arquillian TestRunnerAdaptor. This adaptor is used to manage the Arquillian lifecycle.
  • An ArquillianInterceptor (that references the previously created TestRunnerAdaptor) is established as an interceptor for several Spec method kinds: SETUP_SPEC, CLEANUP_SPEC, SETUP, CLEANUP and FEATURE.
  • When the Sputnik testrunner fires a method of type SETUP_SPEC, the ArquillianInterceptor intercepts this invocation to direct the TestRunnerAdaptor of Arquillian to fires it's BeforeClass event. At this point, managed/embedded containers would be started by Arquillian. A deployment scenario is generated if a @Deployment method is detected, and the created (and enriched) archive is deployed.
  • When the Sputnik testrunner fires a method of type FEATURE, the ClientTestExecutor of Arquillian (that observes the Test event) fires a RemoteExecutionEvent that triggers the RemoteTestExecuter of Arquillian to send a request to execute the desired method on the container. In the container, the ServletTestRunner (present due to the Servlet protocol), delegates the execution of the test method to the SpockTestRunner class (that is deployed along with the Specification classes) on the container.

Comparison with the JBehave extension

In the JBehave integration the Arquillian testrunner performs all the necessary activities of:

  • starting containers,
  • handling @Deployment methods,
  • running the tests (both in-client and in-container),
  • and delegating the actual execution to the Embedder/Embeddable instance.

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.

Feasibility of a Thucydides extension

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment