Execute Cucumber step before/after a specific feature

Dave Novelli picture Dave Novelli · Sep 17, 2013 · Viewed 93.5k times · Source

I want to specify certain setup and tear down steps for each specific feature file. I've seen hooks that allows code to execute before every scenario, and hooks to execute code before each feature, but I want to specify code to run once before and after all scenarios run for one specific feature.

Is this possible?

Answer

Oh Chin Boon picture Oh Chin Boon · Dec 17, 2013

Do you use cucumber-jvm? I found an article that fits your requirement.

http://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/

Basically, do not use JUnit @BeforeClass and @AfterClass for this, as they are unaware of Cucumber Hook Tags. You would want Init and Teardown methods to run for certain scenarios only right?