java 代码的空手道测试是否有可能获得代码覆盖率?

Is it possible to get code coverage with karate tests for java code?

我正在尝试使用空手道测试用例获取 java 代码的测试代码覆盖率。我知道 Junit 是单元测试和代码覆盖率的最佳方法,但我需要专门这样做,因为我想测试 java 代码并通过空手道测试用例获得覆盖率。我能够 运行 空手道测试用例并获得黄瓜 HTML 报告和覆盖率报告(由 jacoco 插件提供)但未显示空手道测试用例覆盖率。我需要知道这是否可能,如果可能,那么我需要做什么changes/additions。

空手道特征文件代码

Feature: Test ElasticUtilsProperties
 
      Background:
        * def ElasticUtilsProperties = Java.type('com.staff.util.ElasticUtilsProperties')
        * def elasticProps = new ElasticUtilsProperties()
        
      Scenario: Get Host
          Given elasticProps.setHost("host-1")
           When def host = elasticProps.getHost()
           Then print 'host-->', host
        
      Scenario: Get Port
          Given elasticProps.setPort("host-1")
           When def port = elasticProps.getPort()
           Then print 'port-->', port
      
      Scenario: Get Scheme
          Given elasticProps.setScheme("scheme")
           When def scheme = elasticProps.getScheme()
           Then print 'scheme-->', scheme
      
      Scenario: Get trustStorePath
          Given elasticProps.setTrustStorePath("trustStorePath")
           When def trustStorePath = elasticProps.getTrustStorePath()
           Then print 'trustStorePath-->', trustStorePath
      
      Scenario: Get trustStorePass
          Given elasticProps.setTrustStorePass("trustStorePass")
           When def trustStorePass = elasticProps.getTrustStorePass()
           Then print 'trustStorePass-->', trustStorePass
      
      Scenario: Get pathPrefix
          Given elasticProps.setPathPrefix("PathPrefix")
           When def pathPrefix = elasticProps.getPathPrefix()
           Then print 'pathPrefix-->', pathPrefix
      
      Scenario: Get index
          Given elasticProps.setIndex("Index")
           When def index = elasticProps.getIndex()
           Then print 'Index-->', index
      
      Scenario: Get RestHighLevelClient
          Given elasticProps.setHost("host-1")
           When def host = elasticProps.getHost()
           Then print 'host-->', host

Java 文件代码

import org.elasticsearch.client.RestHighLevelClient;

public class ElasticUtilsProperties {
private String host;
private int port;
private String scheme;
private String trustStorePath;
private String trustStorePass;
private String pathPrefix;
private String index;
private RestHighLevelClient restHighLevelClient;

public String getHost() {
    return host;
}

public void setHost(String host) {
    this.host = host;
}

public int getPort() {
    return port;
}

public void setPort(int port) {
    this.port = port;
}

public String getScheme() {
    return scheme;
}

public void setScheme(String scheme) {
    this.scheme = scheme;
}

public String getTrustStorePath() {
    return trustStorePath;
}

public void setTrustStorePath(String trustStorePath) {
    this.trustStorePath = trustStorePath;
}

public String getTrustStorePass() {
    return trustStorePass;
}

public void setTrustStorePass(String trustStorePass) {
    this.trustStorePass = trustStorePass;
}

public String getPathPrefix() {
    return pathPrefix;
}

public void setPathPrefix(String pathPrefix) {
    this.pathPrefix = pathPrefix;
}

public String getIndex() {
    return index;
}

public void setIndex(String index) {
    this.index = index;
}

public RestHighLevelClient getRestHighLevelClient() {
    return restHighLevelClient;
}

public void setRestHighLevelClient(RestHighLevelClient restHighLevelClient) {
    this.restHighLevelClient = restHighLevelClient;
}
}

我认为这与 Eclipse 或 JUnit 无关 - 这是一个 Maven 问题。

可用的最佳参考是:https://github.com/intuit/karate/tree/master/karate-demo#code-coverage-using-jacoco

您也可以尝试搜索其他答案:https://whosebug.com/search?q=%5Bkarate%5D+coverage

但我认为您必须自己解决这个问题。如果您在这里 post 您的发现是为了其他人的利益,那就太好了 :)