我想在我的步驟定義中使用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'在我的答案的後半部分。我現在糾正了它。 –