I have an Android project written in Java that I'm working on in Android Studio.
I'd like to use Cucumber for integration testing of some internal components (note: I know this is not the BDD way, nonetheless useful to me). I want the tests to run as local unit tests (without Instrumentation) using gradlew test
because the components under test do not interact with the Android SDK.
My problem is that the Cucumber features are not recognized by Gradle and do not run when I run gradlew test
.
Here's how I set it up so far:
Added these dependencies to my app's build.gradle:
testImplementation 'io.cucumber:cucumber-java:3.0.2' testImplementation 'io.cucumber:cucumber-junit:3.0.2' testImplementation 'io.cucumber:cucumber-jvm:3.0.2'
Also there, I added the path to where I've put my Feature file:
android { ... sourceSets { test { assets.srcDirs = ['src/test/java/integrationTest/assets'] } } }
This is based on this folder structure:
Added a class for the steps (
Steps1.java
) as can be seen above.
What am I missing here?
Your feature files are probably not getting picked up because you did not include a runner. You can either create a JUnit Runner or use the Gradle cucumber plugin. I am not sure if either would work in Android though.
Also you don't need
io.cucumber:cucumber-jvm:3.0.2
as a dependency. It is only a pom.I've found out how to configure my Android app to run my Cucumber tests as "local unit tests" when I run
gradlew test
from the command line. This is based on my SO question here and I've written a "HOWTO" blog post about it here: Android: Run Cucumber tests without a device or an emulator.The key to getting it done is in the app's
build.gradle
file. By latching on to theunitTests.all
hook in thetestOptions
section I am able to run Cucumber usingjavaexec
like so: