这里拿官网的示例 is_it_friday_yet.feature 来跑~并计算Coverage~~
代码
is_it_friday_yet.feature

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

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();
}
}
执行结果
点击Scenario左侧的??执行该Scenario,出现下图则执行成功

计算该场景的Coverage

?会发现...跑了个寂寞,啥都木有

如何解决Coverage都是0的问题
1. 配置Configurations

2. 将逻辑代码所在的包添加到include中

就是这个样纸:

3. 记得勾选Enable coverage in test folder(这里绊了我好久= =)

?4. 再重新执行Run xxx with Coverage

铛铛铛~~撒花🎉🎉🎉~~~
|