prashant-ramcharan / courgette-jvm-example

Courgette-JVM Example
6 stars 1 forks source link

Where to define Cucumber hooks? #9

Closed mycargus closed 2 years ago

mycargus commented 2 years ago

Hello!

Just getting started with courgette and loving it. Having trouble with Cucumber hooks though. When I define Cucumber @Before and @After hooks inside a class, courgette doesn't use them:

import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;

public class CucumberHook {
    @Before
    public void before(Scenario scenario) { ... }

    @After
    public void after() { ... }
}

I also tried defining these Cucumber hooks inside my courgette-annotated class, same result. Defining Cucumber hooks inside each step definition file works fine but I'd like to avoid the added maintenance if possible.

I looked through the courgette docs and dove into the courgette source code a little. Any suggestions? Am I missing something?

Thank you for a useful tool!

prashant-ramcharan commented 2 years ago

Hello,

Cucumber hooks are only used by Cucumber so when you use the @Before or @Afrer hook it's Cucumber that will run the code within these blocks.

Is your CucumberHook class defined in your Cucumber Glue ?

Example with Cucumber Hooks https://github.com/prashant-ramcharan/courgette-jvm-example/blob/master/src/test/java/steps/TestSteps.java#L19-L39

The runner pointing to the package where the Cucumber hooks are implemented https://github.com/prashant-ramcharan/courgette-jvm-example/blob/master/src/test/java/suites/junit/ScenarioSuite.java#L22

mycargus commented 2 years ago

Ah, I see. You're right, the CucumberHook class wasn't included in the Cucumber Glue definition. Somehow that class and its hooks worked without being included in the Cucumber Glue definition before I introduced courgette-jvm. Regardless, this current behavior makes sense to me.

Thank you for your help and for explaining!