![](/img/trans.png)
[英]Cucumber test for Spring Boot can run in “mvn test” but not in “mvn verify”
[英]Is it possible to configure cucumber to run the same test with different spring profiles?
我有一個應用程序,我正在使用不同的技術進行試用。 我有一套用每種技術實現的接口,我使用彈簧配置文件來決定運行哪種技術。 每種技術都有自己的Spring java配置,並使用它們所處的配置文件進行注釋。
我運行我的黃瓜測試,定義哪個配置文件是活動配置文件,但這會強制我每次要測試不同的配置文件時手動更改字符串,從而無法對所有配置文件運行自動測試。 在黃瓜中是否有提供一組配置文件,因此每個測試運行一次?
謝謝!
你有兩種可能性
在第一種情況下 ,它將如下所示。 缺點是您必須為每個跑步者定義不同的報告,並為每個配置提供幾乎相同的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和項目的瓜根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 {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.