I'm trying to get test code coverage for java code using the karate test cases. I know Junit is the best approach for unit testing and code coverage but I need to do this specifically because I want to test the java code and get coverage through karate test cases. I am able to run the karate test case and get the cucumber HTML report and coverage report(provided by jacoco plugin) but karate test case coverage is not shown. I need to know if this is possible or not and if it is possible then what changes/additions do I need to make.
Karate feature file code
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 file code
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;
}
}