我有一个应用程序,我正在使用不同的技术进行试用。我有一套用每种技术实现的接口,我使用弹簧配置文件来决定运行哪种技术。每种技术都有自己的Spring java配置,并使用它们所处的配置文件进行注释。
我运行我的黄瓜测试来定义哪个配置文件是活动配置文件但这会强制我每次想要测试不同的配置文件时手动更改字符串,从而无法对所有配置文件运行自动测试。在黄瓜中是否有提供一组配置文件,因此每个测试运行一次?
谢谢!
答案 0 :(得分:3)
你有两种可能性
在第一种情况中,它将如下所示。缺点是您必须为每个跑步者定义不同的报告,并为每个配置提供几乎相同的Cucumber跑步者。
以下是类的外观:
CucumberRunner1.java
@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.abc.def", "com.abc.common"},
features = {"classpath:com/abc/def/",
"classpath:com/abc/common.feature"},
format = {"json:target/cucumber/cucumber-report-1.json"},
tags = {"~@ignore"},
monochrome = true)
public class CucumberRunner1 {
}
StepAndConfig1.java
@ContextConfiguration(locations = {"classpath:/com/abc/def/configuration1.xml"})
public class StepsAndConfig1 {
@Then("^some useful step$")
public void someStep(){
int a = 0;
}
}
CucumberRunner2.java
@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.abc.ghi", "com.abc.common"},
features = {"classpath:com/abc/ghi/",
"classpath:com/abc/common.feature"},
format = {"json:target/cucumber/cucumber-report-2.json"},
tags = {"~@ignore"},
monochrome = true)
public class CucumberRunner2 {
}
OnlyConfig2.java
@ContextConfiguration(classes = JavaConfig2.class)
public class OnlyConfig2 {
@Before
public void justForCucumberToPickupThisClass(){}
}
第二种方法是使用支持多种配置的自定义黄瓜转轮。您可以自己编写或准备一个,例如,我的 - CucumberJar.java和项目cucumber-junit的根。 在这种情况下,Cucumber runner将如下所示:
CucumberJarRunner.java
@RunWith(CucumberJar.class)
@CucumberOptions(glue = {"com.abc.common"},
tags = {"~@ignore"},
plugin = {"json:target/cucumber/cucumber-report-common.json"})
@CucumberGroupsOptions({
@CucumberOptions(glue = {"com.abc.def"},
features = {"classpath:com/abc/def/",
"classpath:com/abc/common.feature"}
),
@CucumberOptions(glue = {"com.abc.ghi"},
features = {"classpath:com/abc/ghi/",
"classpath:com/abc/common.feature"}
)
})
public class CucumberJarRunner {
}