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.
Add this to your app build.gradle
dependencies.
ext.pickleVersion = '1.0.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.fourlastor:pickle-plugin:$pickleVersion'
}
}
dependencies {
androidTestImplementation 'com.fourlastor:pickle-lib:$pickleVersion'
androidTestAnnotationProcessor 'com.fourlastor:pickle-processor:$pickleVersion'
}
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 {
featuresDir = 'features' // location of features inside `androidTest/src/assets`
packageName = 'com.example.test' // package where tests will be generated
strictMode = false // activate/deactivate strict mode (optional, defaults to true)
}
Test will be generated and you can run them as you would run normal Android Tests 🎉
Disabling strict mode will generate tests only for defined scenarios, a scenario is considered defined if all the steps and background steps for that scenario are defined. The default behavior (strict) will fail at compile time if some scenarios aren't defined.
There are 3 modules: library, plugin, and annotation processor.
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.
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).
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.