bugCracker
bugCracker

Reputation: 3796

Why do we need to write lambda step def inside constructor in cucumber jvm 8?

In new cucumber jvm 8 i see lots of example of hooks and step definition using lambda but they all written inside constructor. is there any reason we nee to write inside constructor? or can we write step definition and hooks using lambda expression but outside constructor?

Upvotes: 1

Views: 304

Answers (1)

Alexey R.
Alexey R.

Reputation: 8676

When you write a step definition it has to be registered in LamdbaGlueRegistry. You can find the details in io.cucumber.java8.En default implementations.

Hence you have to execute that code somehow. The simplest way is to execute it from constructor since Cucumber instantiate all classes that are under glued packages on each scenario run.

Theoretically you can use the same code to register the definitions at any other point. The only thing you have to make sure that the registry has been initialized and your code is reachable from Cucumber entry point.

Upvotes: 2

Related Questions