Search code examples
gradleautomated-testscucumberbuild.gradlecucumber-jvm

Change glue in build.gradle


How can I change the glue path for a Gradle+Cucumber project?

This is the relevant part of a build.gradle file:

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast{
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/main/java/features']
        }
    }
}

When I run the >gradle cucumber from the command line, I get notified scenarios are not defined, because glue file is not in the /main folder, rather in /main/java/stepmethods.

How do I tell that to Gradle?


Solution

  • Let us say that you have a project named acmetesting. Your project structure might look like:

    acmetesting
      |
      +---src/main/java
           |
           +---com.acme.testing
                |
                +---steps
                     |
                     +---cucumberjvm302testbed
                          |
                          +---Cucumber302TestBedSteps.java
    

    File Cucumber302TestBedSteps.java is your step definitions file and in the above configuration it would start off like:

     package com.acme.testing.steps.cucumberjvm302testbed;
    
     import cucumber.api.java.en.Given;
     import cucumber.api.java.en.Then;
     import cucumber.api.java.en.When;
    
     import io.cucumber.datatable.DataTable;
     import io.cucumber.datatable.DataTable.TableConverter;
     import io.cucumber.datatable.DataTableType;
     import io.cucumber.datatable.DataTableTypeRegistry;
     import io.cucumber.datatable.DataTableTypeRegistryTableConverter;
     import io.cucumber.datatable.TableEntryTransformer;
    
     import static org.junit.Assert.assertEquals;
    
     import java.util.HashMap;
     import java.util.List;
     import java.util.Locale;
     import java.util.Map;
     ooo
    

    So your args line would look like:

    args = ['--plugin', 'pretty', '--glue', 'com.acme.testing.steps', 'src/main/java/features']
    

    EDIT I removed cucumberjvm302testbed from the glue value to increase flexibility when other folders are added to steps.