Global Hooks in Cucumber JVM

Hemanth Sridhar
1 min readSep 15, 2019

One important feature in my opinion that is missing in Cucumber JVM at the moment are global hooks (beforeAll and afterAll).

To ensure we get the global hooks feature, we implement the Base Class with ConcurrentEventListener interface and define setEventPublisher method. After this is done, we add this class as a plugin.

This has been tested with cucumber-4. This works even if the tests are running are in parallel.

All the cucumber dependencies are provided below.

The BaseClass will implement ConcurrentEventListener. Since, ConcurrentEventListener is an interface we have to define setEventPublisher method. A complete implementation is provided below.

Now the most important thing is we need to add the above class as a plugin. Otherwise, this approach will not work.

--

--

Hemanth Sridhar
Hemanth Sridhar

Written by Hemanth Sridhar

Staff Software Engineer @Harness

Responses (2)