[Cucumber-jvm][JUnit] Event Handling

244 views
Skip to first unread message

Jaysef

unread,
Nov 29, 2017, 4:48:38 AM11/29/17
to Cukes
Hi everyone,

Does anyone know how events work ? How do I handle them ?


I read the event protocol ( https://docs.cucumber.io/event-protocol/ ), but i still don't understand how to implement any handler (or listener ?). 

With a previous version of cucumber, someone implements his CustomCucumber class adding his CustomListener in that class ( https://www.youtube.com/watch?v=iudFtypIMF0&t=519s ). So I try the same with the new version of Cucumber, and I see that in the listener i can override methods like "testRunStarted" or "testRunFinished" which has the same name of some of the events, but there are no other methods corresponding the rest of the new events. 

I'm sure i'm doing things wrong, so any help is appreciated, thanks


MP Korstanje

unread,
Nov 30, 2017, 2:28:24 PM11/30/17
to Cukes
JUnit events are not the same as the cucumber events and I would not recommend following the listener approach from the Youtube video. While the Cucumber class is part of the public API is hasn't been designed for extension. The the possibility to extend the junit runner might be deprecated and eventually removed all together in the future.

The recommended way to observe the cucumber process is by using a plugin. And you can handle events by writing a custom plugin that implements Formatter. You can then activate this plugin by using the `--plugin com.example.package.of.MyCustomFormatter`. For an example see the JSONFormatter.

Goodluck,
RIen
Reply all
Reply to author
Forward
0 new messages