我想在我的步骤定义中使用DI。我有一个模块,配置黄瓜guice
public class MyModule extends AbstractModule
{
private final static MyInterface INSTANCE = new MyInterfaceImpl();
@Override
protected void configure()
{
bind(MyInterface.class).toInstance(INSTANCE);
}
}
并希望在步骤定义的构造函数中注入此实例。
public class MyStepDefs
{
private final MyInterface instance;
@Inject
public MyStepDefs(MyInterface instance)
{
this.instance = instance
}
}
我想我需要使用cucumber-guice.properties文件来配置GuiceFactory,但我真的不知道这是什么?目前我得到的错误是,
java.lang.NoClassDefFoundError: javax/inject/Singleton
at cucumber.runtime.java.guice.GuiceFactory$CucumberModule.configure(GuiceFactory.java:86)
我也应该使用提供商的建设者注射?
在我来说,我只是用'cucumber.properties'并设置 'guice.injector源= com.xxx.yyy.inject.MyInjectorSource'内'的src /测试/ resources' –
呀对不起 - 我不小心写了“ guice.properties'在我的答案的后半部分。我现在纠正了它。 –