Giter Site home page Giter Site logo

gherkplugin's Introduction

GherkPlugin

Gradle Plugin to generate kotlin code from Gherkin files

This plugin is intended to simplify Acceptance Test generation in Android Kotlin projects. The plugin parses all .feature files in the project generating support classes and functions

Getting Started

In order to start using the plugin you need to add this to your buildscript.

repositories {
    maven { 
        url "https://plugins.gradle.org/m2/"  
      }
}
dependencies {
    classpath "gradle.plugin.com.easycode:gherk:0.7.4"
}

Apply the plugin in your project build.gradle.

apply plugin: 'com.easycode.gherk'

Configuration

The plugin configuration is implemented inside a gherk block:

gherk {
    outputDirectory = File(%OUTPUT_FOLDER%) // default = $buildDir/generated/gherk/src/
    featureDirectory = File(%INPUT_FOLDER%) // default = $projectDir/src/androidTest/assets/
    reportFolderName = %FOLDER_NAME // default = /data/%com.test.app%/cache/gherk-report/
}
  • outputDirectory represents the folder where support kotlin files will be generated.
  • featureDirectory is explored recursively to get all files ending with ".feature"
  • reportFolderName is the name of the folder in the path "${context.cacheDir.absolutePath}/$reporFolderName$gherk_report.json"

Running

The plugin allows you to stablish a relationship between Gherkin Code (Test definition) and Test Implementation Code in the same way Cucumber does. This approach avoid the need to use any custom InstrumentationTestRunner, and there is no need to overwrite AndroidTestRunner.

Given the following feature

Feature: Going to walk

  Scenario: snowing
   Given it is snowing
   When I walk into the street
   Then I should have my umbrella

The code generated allow to write tests in the following way:

@RunWith(AndroidJUnit4::class)
class ExampleTestClass {

  @Test
  fun testSnowing() = test_Snowing {
      given_It_Is_Snowing { 
          //TODO
      }

      when_I_Walk_Into_The_Street { 
          //TODO 
      }

      then_I_Should_Have_My_Umbrella { 
          //TODO 
      }
  }

}

The method "test_Snowing" is storing the correct executing order defined in Gherkin template.

Backgrounds

Some scenarios under the same feature share a common background.

Given the following feature:

Feature: Going to walk with background

 Background: going out
   When I Walk into the street

  Scenario: snowing with background
    Given it is snowing
    Then I should have my umbrella

The way to implement these cases is the following:

@RunWith(AndroidJUnit4::class)
class ExampleTestClass {

    val background = backgroundGoingToWalkWithBackground {

       when_I_Walk_Into_The_Street {
           //TODO
       }
    }

   @Test
   fun testSnowingWithBackground() = test_Snowing_With_Background(background){

       given_It_Is_Snowing { 
            //TODO
       }

       then_I_Should_Have_My_Umbrella {
            //TODO
       }
   }

}

Outlines

Sometimes an scenario includes an array of examples to be acomplished in the test. The plugin generate the code necessary to run the defined examples in the test. A loop iterate over the examples and run the same code multiple times passing the tagged data as arguments of the functions.

Given this outline feature

Feature: Going to walk

  Scenario Outline: weather
     Given It is <weather>
     Then I should should wear <clothes>

  Examples:
    | weather  | clothes |
    |  sunny   | t-shirt |
    |  cloudy  |  coat   |
@RunWith(AndroidJUnit4::class)
class ExampleTestClass {

    @Test
    fun testOutline() = test_Weather { 
        given_It_Is_Weather { weather ->  
            //TODO
        }
        then_I_Should_Should_Wear_Clothes { clothes ->
            //TODO
        }
    }
}

Version

Current version is 0.7.4

Author

JoshDur [email protected]

License

This project is licensed under the Apache 2.0 License. See License for details

gherkplugin's People

Contributors

joshdur avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.