Cucumber JVM:避免 Picocontainer 对未标记为执行的功能进行依赖注入
Cucumber JVM : avoid dependency injection by Picocontainer for features not tagged for execution
假设我有一个标记为 @api
的 Cucumber 特征
@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
...
执行步骤如下:
public class ApiSteps implements En {
public ApiSteps (ABCinjected abcInjected) {
Given("^the initial flow start URL $", () -> {});
When("^I enter that \"([^\"]*)\" into my browser$", abcInjected::navigateToAuthenticationPage);
...
}
即使我通过指定不同的 Cucumber 标签或显式指定 tags = {"not @api"}
来定义此功能不执行,尽管步骤本身不执行,Picocontainer 仍然创建并注入 ABCinjected 的实例 class,这是不可取的。是否可以控制这种行为?我假设如果功能被标记为不执行并且相关 scenario/steps 被忽略,连续 DI 不应该发生。
我在 Github 上收到了 Cucumber 贡献者的回复:
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.
另一个建议是为步骤(api、单位等)设置不同的包,并在运行时设置不同的粘合。
假设我有一个标记为 @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
...
执行步骤如下:
public class ApiSteps implements En {
public ApiSteps (ABCinjected abcInjected) {
Given("^the initial flow start URL $", () -> {});
When("^I enter that \"([^\"]*)\" into my browser$", abcInjected::navigateToAuthenticationPage);
...
}
即使我通过指定不同的 Cucumber 标签或显式指定 tags = {"not @api"}
来定义此功能不执行,尽管步骤本身不执行,Picocontainer 仍然创建并注入 ABCinjected 的实例 class,这是不可取的。是否可以控制这种行为?我假设如果功能被标记为不执行并且相关 scenario/steps 被忽略,连续 DI 不应该发生。
我在 Github 上收到了 Cucumber 贡献者的回复:
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.
另一个建议是为步骤(api、单位等)设置不同的包,并在运行时设置不同的粘合。