GISer在Java开发路上的摸爬滚打

Cucumber Test的Coverage都是0怎么办...

2022-06-15  本文已影响0人  OQOooo

这里拿官网的示例 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();
    }
}
 

执行结果

点击Scenario左侧的▶️执行该Scenario,出现下图则执行成功


image.png

计算该场景的Coverage

image.png

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


image.png

如何解决Coverage都是0的问题

  1. 配置Configurations
image.png

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

image.png

就是这个样纸:

image.png

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


image.png

4. 再重新执行Run xxx with Coverage

image.png

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

上一篇 下一篇

猜你喜欢

热点阅读