我相信这是一个非常特殊的情况,但是我正在为我们使用的某些第三方应用程序构建一些黄瓜测试。
由于我不是真正在测试自己的应用程序,因此我创建了一个maven项目,并将黄瓜配置为在主文件夹(而不是测试文件夹)中运行。
这是我的入口点类:
@SpringBootApplication
public class ExecutableMain implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ExecutableMain.class, args);
}
@Override
public void run(String... args) {
// args logic...
JUnitCore.runClasses(MyCucumberTest.class);
}
}
我的考试班:
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "html:target/cucumber", "json:target/cucumber/cucumber.json"},
glue = {"cucumber.app", "cucumber.steps"}
)
public class MyCucumberTest {
@AfterClass
public static void tearDown(){
// quit the browser
}
}
这目前可以正常工作,但是我想在测试中添加spring功能。 具体来说,我想在黄瓜步骤中自动接线。
Stepdefs:
public class MyStepdefs {
@Autowired
private ConfigProperties properties;
@Given("^Something")
public void example() {
//...
}
我到处搜索,发现有人说我应该在步骤中添加ContextConfiguration批注。我是这样做的:
@ContextConfiguration(classes = ExecutableMain.class, loader = SpringBootContextLoader.class)
public class MyStepdefs {
但这会导致启动过程中出现循环。
我能满足我的需要吗?
答案 0 :(得分:0)
好的,所以我按照https://stackoverflow.com/a/37586547/1031162
基本上我改变了:
return new Observable<string>(obs=>{
const file = (fileChangeEvent.target as HTMLInputElement).files[0];
let fileReader = new FileReader();
fileReader.onload = (e) => {
obs.next(fileReader.result as string);
}
fileReader.readAsText(file);
})
收件人:
@ContextConfiguration(classes = ExecutableMain.class, loader = SpringBootContextLoader.class)
我不是100%知道它如何/为什么起作用,但是确实如此。