cucumbercucumber-jvmpicocontainer

Cucumber JVM : avoid dependency injection by Picocontainer for features not tagged for execution


Assuming that I have a Cucumber feature tagged @api

@api
Feature: BankID authentication

  Scenario Outline: Successful authentication of user using BankID

    Given the initial flow start URL 
    When  I enter that "<url>" into my browser
    ...

and steps for execution as below:

public class ApiSteps implements En {
    public ApiSteps (ABCinjected abcInjected) {
        Given("^the initial flow start URL $", () -> {});
        When("^I enter that \"([^\"]*)\" into my browser$", abcInjected::navigateToAuthenticationPage);
        ...
    }

Even if I define this feature not to be executed by specifying different Cucumber tags or explicitly specifying tags = {"not @api"} , although steps themselves are not executed per se, Picocontainer still creates and injects instance of ABCinjected class, which is undesirable. Is it possible to control this behavior? I assume if feature is tagged as not to be executed and related scenario/steps are ignored, consecutively DI should not happen.


Solution

  • I got response from Cucumber contributor on Github:

    When using lamda steddefs the class has to be instantiated to register the steps. And we would need to know the steps defined by the class to determine if we should instantiate it. This is a dead lock of requirements.

    Another recommendation is to set different packages for steps (api, units etc) and set different glue on runtime.

    https://github.com/cucumber/cucumber-jvm/issues/1672