Skip to content
Advertisement

Why does cucumber run @Before in all glue code files

I have a problem with my cucumber tests. It runs the @Before method in all the glue classes.

For example. This feature file have one glue code in the MainStepDef.class.

JavaScript

The MainStepDef:

JavaScript

I have an additional glue file called: OtherStep.class

JavaScript

And finally I have my runner class.

JavaScript

When I run this I get the runtime exception from the OtherStepDef setup method.

Why does this happen? Should it not execute only the glue needed for the feature?

Example project: https://github.com/cannibalcow/cucumberproblem

Advertisement

Answer

This is the intended behaviour of Cucumber: https://groups.google.com/forum/#!topic/cukes/7gILvMsE2Js

This is the intended behaviour of the @Before and @After hooks: they are not related to each step definition. Every hook is run on each scenario (unless it’s filtered out by tags).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement