這里拿官網(wǎng)的示例 is_it_friday_yet.feature 來跑~并計算Coverage~~
代碼
is_it_friday_yet.feature

image.png
Feature: Is it Friday yet?
Everybody wants to know when it's Friday
Scenario: Sunday isn't Friday
Given today is Sunday
When I ask whether it's Friday yet
Then I should be told "Nope"
StepDefinitions.java

image.png
public class StepDefinitions {
@Given("today is Sunday")
public void today_is_sunday() {
System.out.println("today_is_sunday");
// Write code here that turns the phrase above into concrete actions
// throw new io.cucumber.java.PendingException();
}
@When("I ask whether it's Friday yet")
public void i_ask_whether_it_s_friday_yet() {
System.out.println("i_ask_whether_it_s_friday_yet");
// Write code here that turns the phrase above into concrete actions
// throw new io.cucumber.java.PendingException();
}
@Then("I should be told {string}")
public void i_should_be_told(String string) {
System.out.println("i_should_be_told");
// Write code here that turns the phrase above into concrete actions
// throw new io.cucumber.java.PendingException();
}
}
執(zhí)行結果
點擊Scenario左側的??執(zhí)行該Scenario,出現(xiàn)下圖則執(zhí)行成功

image.png
計算該場景的Coverage

image.png
會發(fā)現(xiàn)...跑了個寂寞,啥都木有

image.png
如何解決Coverage都是0的問題
- 配置Configurations

image.png
2. 將邏輯代碼所在的包添加到include中

image.png
就是這個樣紙:

image.png
3. 記得勾選Enable coverage in test folder(這里絆了我好久= =)

image.png
4. 再重新執(zhí)行Run xxx with Coverage

image.png
鐺鐺鐺~~撒花??????~~~