Git Product home page Git Product logo

pickle's Introduction

Pickle

Lib Plugin Processor
Download Download Download

Pickle is an implementation of Cucumber for Android which generates the tests classes at compile time instead of runtime.

The main advantage over cucumber-android is that you won't need to use a different instrumentation runner for your Cucumber tests, and that, being generated, you can debug and inspect the tests, which makes it easier to debug errors.

Installation

Add this to your app build.gradle dependencies.

ext.pickleVersion = '1.3.2'
ext.cucumberVersion = '4.4.0' // Last supported version. Do not use never versions since annotation packages were moved.

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath "com.fourlastor:pickle-plugin:$pickleVersion"
  }
}

dependencies { 
  androidTestImplementation "io.cucumber:cucumber-java:$cucumberVersion"
  androidTestImplementation "com.fourlastor:pickle-lib:$pickleVersion"
  androidTestAnnotationProcessor "com.fourlastor:pickle-processor:$pickleVersion"
  
  // For Kotlin projects with `kapt`
  // kaptAndroidTest "com.fourlastor:pickle-processor:$pickleVersion"

}

If you enable pickle on unit tests (see configuration below), remember to apply the annotation processor on your test variant!

Configuration

Add the following to your app build.gradle

Make sure to apply this plugin before the kotlin plugin, if using one.

apply plugin: 'com.fourlastor.pickle'

pickle {
    packageName = 'com.example.test' // package where tests will be generated
    strictMode = true // activate/deactivate strict mode (defaults to true)
    androidTest {
      enabled = true // enables pickle on androidTest (defaults to true)
      featuresDir = 'features' // location of features inside `androidTest/src/assets`
    }
    unitTest {
      enabled = false // enables pickle on unit tests (defaults to false)
      featuresDir = project.file('src/test/features') // absolute path to location of feature files for unit tests
    }
}

Test will be generated and you can run them as you would run normal Android/unit tests ๐ŸŽ‰

Disabling strict mode will generate tests only for scenario having all the steps/background steps defined, and empty tests annotated with @Ignore for scenario with missing steps. The default behavior (strict) will fail at compile time if some scenarios are missing any step.

Modules

There are 3 modules: library, plugin, and annotation processor.

Library

The library contains only an annotation class (Pickle) which is required for the other 2 modules to work. This class holds the settings passed to the plugin.

Plugin

The plugin is responsible for triggering a new build in case the assets change, and to provide the extension to configure Pickle. It registers a code generation task that will create a new class representing the current state of the assets (contains a hashcode of the files).

Annotation Processor

The annotation processor will look for the hash class generated by the plugin (PickleHash, annotated with Pickle), read the settings from the annotation and generate test classes representing the feature files.

Sample

To open the samples, open a new project in Intellij IDEA and select the sample folder, which contains 2 project: app-kotlin and app-java.

It uses composite builds to load the project's libraries, so you can freely modify them and it will pick them up.

Known Issues

  • Cucumber Expressions are not supported yet. Issue #52.
    • IntelliJ IDEA Plugin recently started to use Cucumber Expressions by default for parameters. Convert them to Regex for Pickle to understand.
  • The package of Given/When/Then annotations were moved with recent Cucumber versions. New locations are not supported yet. Issue #48.

pickle's People

Contributors

fourlastor avatar tasomaniac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pickle's Issues

Gradle 5.2 incompatibility

Bad news! Plugin is no longer compatible with 5.2 because I used internal reflection utilities from Gradle in #7

The whole class JavaReflectionUtil is completely changed into something much more smaller. ๐Ÿ˜ž

I guess that's a good lesson learned.

incompatibility with Gradle 5.1

When using the AndroidStudio 3.4 Canary 10,
and having upgraded to Gradle 5.1-milestone-1,

the following error appears while building:

Caused by: java.lang.NoSuchMethodError: com.android.build.gradle.tasks.MergeSourceSetFolders.getOutputDir()Ljava/io/File;
	at com.fourlastor.pickle.PicklePlugin$configure$1.execute(PicklePlugin.kt:115)
	at com.fourlastor.pickle.PicklePlugin$configure$1.execute(PicklePlugin.kt:23)
	at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:158)
	at com.fourlastor.pickle.PicklePlugin.configure(PicklePlugin.kt:109)
	at com.fourlastor.pickle.PicklePlugin.access$configure(PicklePlugin.kt:23)
	at com.fourlastor.pickle.PicklePlugin$apply$1$1.execute(PicklePlugin.kt:96)
	at com.fourlastor.pickle.PicklePlugin$apply$1$1.execute(PicklePlugin.kt:23)
	at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:158)
	at com.fourlastor.pickle.PicklePlugin$apply$1.execute(PicklePlugin.kt:87)
	at com.fourlastor.pickle.PicklePlugin$apply$1.execute(PicklePlugin.kt:23)

Problem with Before/After annotated methods

Cucumber Before/After methods are supported with pickle. When they are added into Steps files, those before and after methods are just called manually before and after all methods.

They are called just inline in test methods.

But this means that any exception occurring during test execution will not call after method because of the throwing.

Instead, Before/After methods should really be converted into jUnit Before and After methods in the generated code

Unclear processor error

Hey,

It is not so uncommon to have the following mistake:

@Given("^Backend Response for search will be successful$")
public void backendResponseForSearchWillBeSuccessful(String searchKey) {

In this case, the given sentence forget to include the regex to match the String parameter. Processor gives a cryptic error (which is coming from parsing).

Here is the error we got

index 3 for '$S' not in range (received 2 arguments)

Deploy changelog on new tags

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator -u fourlastor -p pickle -t <GITHUB_TOKEN>
  • react to a tag (easy with circleci)
  • use the changelog generator to generate a new changelog
  • create a new branch
  • add CHANGELOG.md to staging
  • commit the new changelog
  • create a PR with the new changelog

Non-strict mode suggestion

Non-strict mode is not so obvious even after introducing a warning in #2

What about still generating the test but putting @Ignore annotation on it? This will also show up in the IDEs and will make it super obvious for users.

Minor indentation issue with error output

The newly added check for arguments mismatch in #12 has an indentation issue shown below. It is minor but would be good to fix.

error:                 Pickle Error:
                  Step definition argument mismatch.
  > Step definition: "display network connection error message"
  > Step implementation: com.example.login.LoginSteps.displayNetworkConnectionErrorMessage(java.lang.String)
2 errors

Cucumber Expressions support

Cucumber released a support for a simpler expressions than using regexes to match for parameters.

It is documented in quite good details here: https://cucumber.io/docs/cucumber/cucumber-expressions/

Early this year, IntelliJ IDEA plugin was also updated to use this by default. What that means is that if you Option+Enter to create Steps in java, it will put Cucumber Expressions by default and that will make Pickle fail.

New configuration does not work.

I'm not sure if it works in Kotlin Gradle DSL but below does not work with Groovy projects.

https://github.com/fourlastor/pickle/#configuration

pickle {
    androidTest {
      featuresDir = 'features' // location of features inside `androidTest/src/assets`
    }
}

The error is:

> Could not find method androidTest() for arguments [setup_bdd_test_8aihs9lwmlmtcmk67w5u4oihx$_run_closure1$_closure4@6b3ad53c] on object of type com.fourlastor.pickle.PicklePlugin$Extension.

No error when 2 scenario names are the same

When 2 scenario names are the same, Pickle generates 2 methods with the same name. This causes compilation error in the generated code. Which is too late.

Ideally, it should warn the user with a clear message.

Logo design

Hi, I'm a logo designer and I can design a free logo for your project. So ,what do you think?

Output warning in non-strict mode

When strictMode is disabled, the errors are just ignored. Instead, it would be good if the annotation processor outputs the missing definitions as a warning.

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.