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

這里拿官網(wǎng)的示例 is_it_friday_yet.feature 來跑~并計(jì)算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í)行結(jié)果

點(diǎn)擊Scenario左側(cè)的??執(zhí)行該Scenario,出現(xiàn)下圖則執(zhí)行成功


image.png

計(jì)算該場(chǎng)景的Coverage

image.png

會(huì)發(fā)現(xiàn)...跑了個(gè)寂寞,啥都木有


image.png

如何解決Coverage都是0的問題

  1. 配置Configurations
image.png

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

image.png

就是這個(gè)樣紙:

image.png

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


image.png

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

image.png

鐺鐺鐺~~撒花??????~~~

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容