Hot questions for Using Cucumber in java 8

Question:

I have the following sample gherkin scenario on my feature file:

Scenario: Book an FX Trade
 Given trades with the following details are created:
   |buyCcy |sellCcy |amount   |date       |
   |EUR    |USD     |12345.67 |23-11-2017 |
   |GBP    |EUR     |67890.12 |24-11-2017 |
 When the trades are executed
 Then the trades are confirmed

In my glue file, I can map the data table to an object Trade as an out of the box cucumber solution:

@When("^trades with the following details are created:$")
public void trades_with_the_following_details_are_created(List<Trade> arg1) throws Throwable {
        //do something with arg1
}

What I want to achieve: Improve the readability of my gherkin scenario by doing the following:

  • Transpose the data table vertically, This will improve readability if my object has around 10 fields
  • Replace fields / column names with aliases

    Sample:

    Scenario: Book an FX Trade
     Given trades with the following details are created:
       |Buy Currency  | EUR        | GBP        |
       |Sell Currency | USD        | EUR        |
       |Amount        | 12345.67   | 67890.12   |
       |Date          | 23-11-2017 | 24-11-2017 |
     When the trades are executed
     Then the trades are confirmed
    

    I want the table to be dynamic in a way that it can have more or less than 2 data sets / columns. What would be the best way to achieve this?

    Additional info: Language: Java 8 Cucumber version: 1.2.5

    Trade POJO being something like:

    public class Trade {
        private String buyCcy;
        private String sellCcy;
        private String amount;
        private String date;
    
        /**
         * These fields are growing and may have around 10 or more....
         * private String tradeType;
         * private String company;
         */
    
        public Trade() {
        }
    
        /**
         * accessors here....
         */
    }
    

    Answer:

    If the table is specified in your feature file as

    |buyCcy  | EUR        | GBP        |
    |sellCcy | USD        | EUR        |
    |amount  | 12345.67   | 67890.12   |
    |date    | 23-11-2017 | 24-11-2017 |
    

    you can use the following glue code (with your posted Trade class, assuming that there is a proper toString() method implemented)

    @Given("^trades with the following details are created:$")
    public void tradeWithTheFollowingDetailsAreCreated(DataTable dataTable) throws Exception {
        // transpose - transposes the table from the feature file
        // asList - creates a `List<Trade>`
        List<Trade> list = dataTable.transpose().asList(Trade.class);
        list.stream().forEach(System.out::println);
    }
    

    output

    Trade{buyCcy=EUR, sellCcy=USD, amount=12345.67, date=23-11-2017}
    Trade{buyCcy=GBP, sellCcy=EUR, amount=67890.12, date=24-11-2017}
    
  • Question:

    I am trying to run my automation code built in cucumber framework by Jenkins job, in which environment variables are set by injecting via build setup. I am getting the following error.

    [EnvInject] - Executing scripts and injecting environment variables after the SCM step.
    [EnvInject] - Injecting as environment variables the properties content 
    PATH=/data/java/jdk180152/bin:/data/build_tools/maven/apache-maven-3.5.2/bin:/data/build_tools/python/python-2.7.14/bin/:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:
    M2_HOME=/data/build_tools/maven/apache-maven-3.5.2
    JDK_HOME=/data/java/jdk180152
    JAVA_HOME=/data/java/jdk180152
    MAVEN_HOME=/data/build_tools/maven/apache-maven-3.5.2
    
    [EnvInject] - Variables injected successfully.
    Parsing POMs
    Established TCP socket on 33831
    [cafeAutomation] $ java -cp /data/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.12-alpha-1.jar:/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven-3.5.2/boot/plexus-classworlds-2.5.2.jar:/data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven-3.5.2/conf/logging jenkins.maven3.agent.Maven35Main /data/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven-3.5.2 /var/cache/jenkins/war/WEB-INF/lib/remoting-3.14.jar /data/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.12-alpha-1.jar /data/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.12-alpha-1.jar 33831
    Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:133)
        at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:64)
    ERROR: ================================================================================
    ERROR: Invalid project setup: Connection reset
    ERROR: Processing failed due to a bug in the code. Please report this to the issue tracker (https://jenkins.io/redirect/report-an-issue).
    java.lang.NullPointerException
        at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:304)
        at hudson.maven.ProcessCache.get(ProcessCache.java:236)
        at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:804)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
        at hudson.model.Run.execute(Run.java:1724)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
        at hudson.model.ResourceController.execute(ResourceController.java:97)
        at hudson.model.Executor.run(Executor.java:421)
    project=hudson.maven.MavenModuleSet@6b7062ed[smr-qa-maven]
    project.getModules()=[hudson.maven.MavenModule@10ea4a41[smr-qa-maven/cafeAutomatin:cafeAutomation][smr-qa-maven/cafeAutomation:cafeAutomation][relativePath:WebApp/Automation Scripts/CAFE Automation Scripts/cafeAutomation]]
    project.getRootModule()=hudson.maven.MavenModule@10ea4a41[smr-qa-maven/cafeAutomation:cafeAutomation][smr-qa-maven/cafeAutomation:cafeAutomation][relativePath:WebApp/Automation Scripts/CAFE Automation Scripts/cafeAutomation]
    FATAL: null
    

    Java version installed on the box - Java 8, Maven - 3.5.2, Jenkins version - 2.89.3

    In my pom.xml file, I have mentioned the plugin as

    <plugin>
    
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.1</version>
    
    <configuration>
    <compilerVersion>1.8</compilerVersion>
    <source>1.8</source>
    <target>1.8</target>
    <fork>true</fork>
                        <executable>/data/java/jdk180152/bin/javac</executable>
    
    </configuration>
    </plugin>
    

    Have also tried by adding the following to the pom file, but still the same error

    <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    

    Answer:

    I have run into the same problem. It was anoying because I was trying to build an existing project which was not changed since over one year. I always got following error:

    Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        at jenkins.maven3.agent.Maven33Main.main(Maven33Main.java:133)
        at jenkins.maven3.agent.Maven33Main.main(Maven33Main.java:64)
    ERROR: ================================================================================
    ERROR: Invalid project setup: Connection reset
    ERROR: [JENKINS-18403][JENKINS-28294] JDK 'JDK7' not supported to run Maven projects.
    ERROR: Maven projects have to be launched with a Java version greater or equal to the minimum version required by the master.
    ERROR: Use the Maven JDK Toolchains (plugin) to build your maven project with an older JDK.
    ERROR: Retrying with slave Java and setting compile/test properties to point to /var/tomcat/java/jdk7/.
    ERROR: ================================================================================
    

    Some one from OPS team had updated jeikins version and that is the clue! I came around following site Maven jobs and Java versions compatibility. The problem is very well described on that site by one sentense:

    Because java serialized classes are exchanged between Jenkins master and Maven Jobs it is required that the JVM used to launch Maven is superior or equal to the version of Java for which Jenkins Master is built for.

    I opened my Jenkins project and changed the "JDK" settings. After changing the java version (in my case to Java 8) everything was fine and my project was building successfully.

    Question:

    The classic way of step definition pre-Java 8 allows you to use the actual keywords of other languages for the annotations.

    @前提("totally new stuff")
    public void totallyNewStuff() {
        System.out.println("hello world")
    }
    

    What would be the equivalent of this as a Java 8 lambda?

    I am assuming that the Cucumber test would work if I were to simply write the step definitions in English like so:

    Given("totally new stuff",() -> System.out.println("hello world"));
    

    But that would defeat the purpose of localized Gherkin.


    Answer:

    For Japanese you implement the Ja interface instead of the En interface. But it's worth nothing that using 前提 or Given makes no functional difference. Steps are matched regardless of keyword.

    import io.cucumber.java8.Ja;
    
    public class RpnCalculatorSteps implements Ja {
        private RpnCalculator calc;
    
        public RpnCalculatorSteps() {
    
            前提("totally new stuff", () -> {
    
            });
        }
    }
    

    Question:

    I using Java 8 with cucumber. It's possible to create lambda expression for Given, When, Then, And, But e.g.

    When("test", (String path) -> this.driver.findElement(By.xpath(path)));

    My question is is it possible to create lambda expression form After and Before instead of @Before("@scenarioTest") or @After("@scenarioTest")?


    Answer:

    If you want to use After/Before without tags you can use

    After(()->{
        YOUR_CODE;
    });
    

    or if you want to pass tags you can do it passing table like this:

    String[] tags = {"@tag1", "@tag2"};
    Before(tags, ()->YOUR_CODE);
    

    Question:

    I've got a cucumber datatable representing an object. Some of the fields need to be Instants, some need to be LocalDates. I was looking around and all the posts about parsing java 8 time objects seem to be from a few years ago and I was wondering if there's a library out there that can handle this for me.


    Answer:

    You may first want to consider if you need to express the exact dates as part of your scenario. If the dates are merely incidental to the scenario you should strongly consider removing them from the feature file.

    But if you must: jackson-databind is the way to go. It is primarily made to (de)serialize POJO's to and from JSON. As Cucumbers data table can be expressed as a list of json maps we can leverage it.

    For this explanation I am assuming you are using Cucumber-JVM 4 and ISO8601 date formats. If you are using other date formats there are other resources to help you with that.

    So lets say you have a step like this:

        Given an object with dates
          | localDate  | instant                  |
          | 2019-09-05 | 2015-06-02T21:34:33.616Z |
    

    First define a step that accepts your object. Your object must be a POJO.

    import io.cucumber.java.en.Given;
    
    import java.time.Instant;
    import java.time.LocalDate;
    
    public class DateSteps {
    
        @Given("an object with dates")
        public void and_object_with_dates(Dates dates) {
    
        }
    
        public static class Dates {
            public LocalDate localDate;
            public Instant instant;
    
        }
    }
    

    Add a dependency on Jackson and JSR310 module to add support for the date time objects added by JSR310.

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.9.8</version>
            </dependency>
    
            <dependency>
                <groupId>com.fasterxml.jackson.datatype</groupId>
                <artifactId>jackson-datatype-jsr310</artifactId>
                <version>2.9.8</version>
            </dependency>
    

    Configure cucumbers type registry to use the object mapper with the JSR310 module enabled to convert data table cells, entries and parameter types.

    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
    import io.cucumber.core.api.TypeRegistry;
    import io.cucumber.core.api.TypeRegistryConfigurer;
    import io.cucumber.cucumberexpressions.ParameterByTypeTransformer;
    import io.cucumber.datatable.TableCellByTypeTransformer;
    import io.cucumber.datatable.TableEntryByTypeTransformer;
    
    import java.lang.reflect.Type;
    import java.util.Locale;
    import java.util.Map;
    
    import static java.util.Locale.ENGLISH;
    
    public class ParameterTypes implements TypeRegistryConfigurer {
    
        @Override
        public Locale locale() {
            return ENGLISH;
        }
    
        @Override
        public void configureTypeRegistry(TypeRegistry typeRegistry) {
            Transformer transformer = new Transformer();
            typeRegistry.setDefaultDataTableCellTransformer(transformer);
            typeRegistry.setDefaultDataTableEntryTransformer(transformer);
            typeRegistry.setDefaultParameterTransformer(transformer);
        }
    
        private static class Transformer implements ParameterByTypeTransformer, TableEntryByTypeTransformer, TableCellByTypeTransformer {
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module());
    
            @Override
            public Object transform(String s, Type type) {
                return objectMapper.convertValue(s, objectMapper.constructType(type));
            }
    
            @Override
            public <T> T transform(Map<String, String> map, Class<T> aClass, TableCellByTypeTransformer tableCellByTypeTransformer) {
                return objectMapper.convertValue(map, aClass);
            }
    
            @Override
            public <T> T transform(String s, Class<T> aClass) {
                return objectMapper.convertValue(s, aClass);
            }
        }
    }
    

    You can now use JSR310 dates everywhere.

    Question:

    I'm doing cucumber bdd tests i have a class [MyClient] that wraps restassured methods and I have multiple classes that calls [MyClient].

    I can do methods like put, post etc. just fine but I am wondering whether there is a way for me to get the actual request fields (header, body...) sent after doing the request.

    I also dont have any problems getting and parsing the response but I'm unable to get the request sent.

    Considering the following, I can call the sendPostRequest() that will store the RequestSpecification instance to a field called request and I can fetch it anytime by calling the getter. However, I cannot take the individual fields from the RequestSpecification object. From the debugger, I can see the fields just fine so I was thinking there has to be some clean way for me to get it.

    I've already tried log() but it doesnt seem to give me what I need. Any help is appreciated!!

    CALLING CLASS:

    public class MyInterfaceSteps() {
     private myClient = new MyClient();
    
     public sendPostRequest(){
      myClient.post(someHeaders, someBody, someUrl);
     }
    }
    

    CLIENT CLASS:

    public class MyClient() {
     private RequestSpecification request;
     private Response response;
    
     public getRequest() {
      return request;
     }
    
     public getResponse() {
      return response;
     }
    
     public Response post(Map<String, String> headers, String body, String url) {
      request = given().headers(headers).contentType(ContentType.JSON).body(body);
      response = request.post(url);  
     }
    }
    

    Answer:

    You create a filter (https://github.com/rest-assured/rest-assured/wiki/Usage#filters) which gives you access to FilterableRequestSpecification (http://static.javadoc.io/io.rest-assured/rest-assured/3.0.3/io/restassured/specification/FilterableRequestSpecification.html) from which you can get (and modify) e.g. headers and body etc. The filter could store these values to a datastructure of your choice.

    Question:

    Getting the below error while running functional test cases after upgrading to jdk10.

    Could not target platform: 'Java SE 10' using tool chain: 'JDK 8 (1.8)'.

    build.gradle

    import com.bmuschko.gradle.docker.tasks.image.Dockerfile
    import java.text.SimpleDateFormat;
    import org.apache.tools.ant.taskdefs.condition.Os
    
    
    buildscript {
        ext {
            springBootVersion = '2.0.1.RELEASE'
        }
        repositories {
            mavenCentral()
            mavenLocal()
            maven {
            url 'https://repo.spring.io/libs-release'
            url 'https://repo.spring.io/release'
            url 'https://repo.spring.io/snapshot'
            url 'https://repo.spring.io/milestone'
            url 'https://repo.spring.io/libs-milestone'
            }
    
            maven{
                url='https://plugins.gradle.org/m2/'
            }
            mavenLocal()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
            classpath ("com.bmuschko:gradle-docker-plugin:3.2.1")
            classpath ("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5")
            classpath "gradle.plugin.au.com.dius:pact-jvm-provider-gradle_2.12:3.6.0-rc.0"
            classpath ("com.moowork.gradle:gradle-node-plugin:1.2.0")
    
        }
    }
    
    plugins {
        id "java"
        id "au.com.dius.pact" version "3.6.0-rc.0"
        id "com.gorylenko.gradle-git-properties" version "1.4.17"
        id "de.undercouch.download" version "3.4.2"
    
    }
    
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'com.bmuschko.docker-remote-api'
    apply plugin: 'jacoco'
    apply plugin: 'maven-publish'
    apply plugin: 'org.sonarqube'
    apply plugin: 'au.com.dius.pact'
    apply plugin: 'scala'
    
    
    group = 'com'
    sourceCompatibility = 10
    
    ext {
        springCloudVersion = 'Finchley.RELEASE'
    }
    
    //start of integration tests changes
    sourceSets {
        integrationTest {
            java {
                compileClasspath += main.output + test.output
                runtimeClasspath += main.output + test.output
                srcDir file('test/functional-api/java')
            }
            resources.srcDir file('test/functional-api/resources')
        }
    }
    
    configurations {
        integrationTestCompile.extendsFrom testCompile
        integrationTestRuntime.extendsFrom testRuntime
    }
    //end of integration tests changes
    dependencies {
        //web (Tomcat, Logging, Rest)
        compile group: 'org.springframework.boot',   name: 'spring-boot-starter-web'
        // Redis
        //compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis'
        //Mongo Starter
        compile group: 'org.springframework.boot', name:'spring-boot-starter-data-mongodb'
    
        // Configuration processor - To Generate MetaData Files. The files are designed to let  developers offer “code completion� as users are working with application.properties
        compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
        // Actuator - Monitoring
        compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
    
        //Sleuth - Tracing
        compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth'
        //Hystrix - Circuit Breaker
        compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix'
        // Hystrix - Dashboard
        compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix-dashboard'
        // Thymeleaf
        compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
        //Voltage
        // Device Detection
    
        compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-cassandra', version:'2.0.4.RELEASE'  
        compile group: 'com.google.guava', name: 'guava', version: '23.2-jre'
        compile('com.google.code.gson:gson:2.8.0')
        compile('org.json:json:20170516')
    
        //Swagger
        compile group: 'io.springfox', name: 'springfox-swagger2', version:'2.8.0'
        compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.8.0'
    
        //jkd10 fixes
        compile group: 'javax.xml.bind',name: 'jaxb-api', version:'2.3.0'
        compile group: 'javax.xml.soap', name: 'javax.xml.soap-api', version:'1.3.5'
        compile group: 'com.sun.xml.messaging.saaj', name: 'saaj-impl', version:'1.4.0'
        compile group: 'javax.activation', name: 'activation', version: '1.1.1'
        compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version:'2.3.0.1'
    
        //Lombok
        compileOnly group: 'org.projectlombok', name: 'lombok',version:'1.18.2'
        //compile group: 'io.smartcat', name: 'cassandra-diagnostics-connector21', version: '1.4.10'
        //Testing
        //Spring  WS Test
        testCompile group: 'org.springframework.ws', name: 'spring-ws-test', version:'2.4.0.RELEASE'
    
        testCompile('org.springframework.boot:spring-boot-starter-test'){
            exclude group: "com.vaadin.external.google", module:"android-json"
        }
        //Pact
        testCompile group: 'au.com.dius', name: 'pact-jvm-provider-gradle_2.12', version: '3.5.7'
        testCompile group: 'au.com.dius', name:'pact-jvm-provider-junit_2.12',version:'3.5.13'
        testCompile group: 'au.com.dius', name:'pact-jvm-consumer-junit_2.12', version:'3.5.13'
    
        //Embedded mongo for testing
        testCompile group: 'de.flapdoodle.embed', name:'de.flapdoodle.embed.mongo',version:'2.0.1'
        //testCompile group: 'cz.jirutka.spring', name: 'embedmongo-spring', version: '1.1'
    
        compile group: 'info.cukes', name: 'cucumber-jvm', version: '1.2.5'
        testCompile group: 'io.cucumber', name: 'cucumber-junit', version: '3.0.2'
        compile group: 'io.cucumber', name: 'cucumber-spring', version: '3.0.2'
    
        testCompile('org.cassandraunit:cassandra-unit-spring:3.5.0.1'){
            exclude group: 'org.cassandraunit', module: 'cassandra-unit'
        }
        // https://mvnrepository.com/artifact/org.cassandraunit/cassandra-unit-shaded
        compile group: 'org.cassandraunit', name: 'cassandra-unit-shaded', version: '3.5.0.1'
        // https://mvnrepository.com/artifact/org.hectorclient/hector-core
        compile group: 'org.hectorclient', name: 'hector-core', version: '2.0-0'
        compile group: 'org.apache.cassandra', name: 'cassandra-all', version: '3.11.3'
        integrationTestCompile group: 'org.springframework.ws', name: 'spring-ws-test', version:'2.4.0.RELEASE' //changes for integration tests
        integrationTestCompile("org.springframework.boot:spring-boot-starter-test"){ //changes for integration tests
            exclude group: "com.vaadin.external.google", module:"android-json"
        }
        //integrationTestCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5' //changes for integration tests
        //integrationTestCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5' //changes for integration tests
    
    }
    
    dependencyManagement {
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        }
    
    }
    
    test {
        //ignoreFailures = true
        reports.junitXml.enabled = false
        reports.html.enabled = true
        testLogging {
            exceptionFormat = 'full'
        }
        jacoco {
            append = false
            destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
            maxHeapSize = '2048m'
            minHeapSize = '1024m'
            //classDumpDir = file("$buildDir/jacoco/classpathdumps")
        }
    }
    jacocoTestReport {
        group = "Reporting"
        reports {
            xml.enabled true
            csv.enabled false
            html.destination "${buildDir}/reports/coverage"
        }
        afterEvaluate {
            classDirectories = files(classDirectories.files.collect {
                fileTree(dir: it,
                        exclude: [
                                    '**/config*',
                                    '**/coupons/TextToClipApplication*',
                                    '**/bean/*Request*',
                                    '**/bean/*Response*',
                        ])
            })
        }
    }
    test.finalizedBy jacocoTestReport
    
    jacoco {
        toolVersion = "0.8.2"
        reportsDir = file("$buildDir/customJacocoReportDir")
    }
    
    //start of changes for integration tests
    task apifunctionaltest(type: Test) {
        systemProperty "integrationurl", System.getProperty("integrationurl")
        reports.junitXml.enabled = false
        reports.html.enabled = true
        testLogging {
            exceptionFormat = 'full'
        }
        testClassesDirs = sourceSets.integrationTest.output.classesDirs
        classpath = sourceSets.integrationTest.runtimeClasspath
        outputs.upToDateWhen { false }
        reports.html.destination = file("${reporting.baseDir}/${name}")
    }
    //end of changes for integration tests
    

    We are using cucumber to test it. Same code is working in local using gradle, but not working in server. Anyone faced the same problem ?


    Answer:

    Thanks everyone. Issue for us is build server has been using jdk8. Now it is resolved after changing the build template to jdk10.