【发布时间】:2016-02-10 12:57:48
【问题描述】:
我使用 Cucumber 和 Guice 作为 DI。
我遇到了以下问题:
我有一个步骤,即
class MyStep() {
@Inject
private MyService myService;
@Given("Some acction happen")
public void sthHappen() {
myService.doSth();
}
}
我已经让这个类作为JUnit test 运行它
@RunWith(Cucumber.class)
@CucumberOptions(...)
public class MyTest {
}
有一个
class MyModule extends AbstractModule {
@Override
protected void configure() {
bind(MyService.class).to(MyFirstService.class);
}
}
这是我的MyInjectorSource使用的
我定义 cucumber.properties 我定义 guice.injector-source=MyInjectorSource;
还有一个带有场景的功能文件。
目前一切正常。
不,我想与其他 MyService 实现一起运行 MyStep 步骤(当然我不会复制 MyStep 的代码) 我定义了一个包含新场景和新测试类的新功能文件
@RunWith(Cucumber.class)
@CucumberOptions(...)
public class MyOtherTest {
}
现在我尝试创建另一个InjectorSource,但无法配置它。
【问题讨论】:
-
如果将“@Inject”注释放在“@Before”挂钩中会怎样?您可以根据标签创建不同的“@Before”挂钩,例如“@Before”(“@tag1”)和“@Before”(“@tag2”)。每个都有不同的“@Inject”定义。
-
如何在评论中转义“@”?
标签: java cucumber guice cucumber-junit