Skip to main content

cucumber-jvm and Android Studio

During this Winter holidays, I've been exploring a Behavior Driven Development and experimented with a couple of testing frameworks: Calabash and cucumber-jvm.

In this post, I would like to describe setting up cucumber-jvm for Android Studio projects.

I've extended cucumber-jvm examples with a version for Android Studio. Here is a copy in my github branch:

In addition to the example code, here is some details on how it was created.


The cucumber-jvm requires several libraries to be added to a project:

I've found it's easier to add those dependencies with the Android Studio project setup dialog because it takes care of the jar versions for you.

File > Project Structure > Modules > app > Dependencies > + > Library dependency
  > type "cucumber" in the search dialog and submit a search request
  > select

 Make sure to set the scope for the libs as Test compile:

The cucumber-android.jar contains an apklib. Turns out Android Studio does not support it yet. Please see this post for more details.

A workaround is to build the jar yourself or just append @jar to the dependency:

androidTestCompile 'info.cukes:cucumber-android:1.2.0@jar'

Note, the `@jar` suffix is required in order to use the embedded jar file.

If you like to build the jar yourself, make a copy of cucumber-jvm

git clone

Build cucumber-android jar following the steps described here:

Copy the jar:

cp android/target/cucumber-android-1.2.1-SNAPSHOT.jar you_project/app/libs

Add a dependency on a jar file to your project

File > Project Structure > Modules > app > Dependencies > + > File dependency
> select the cucumber-android-1.2.1-SNAPSHOT.jar
> select Test compile scope.

Once this is done, the build.gradle should have something like this:

dependencies {
    androidTestCompile 'info.cukes:cucumber-core:1.2.0'
    androidTestCompile 'info.cukes:cucumber-html:0.2.3'
    androidTestCompile 'info.cukes:cucumber-java:1.2.0'
    androidTestCompile 'info.cukes:cucumber-junit:1.2.0'
    androidTestCompile 'info.cukes:cucumber-jvm-deps:1.0.3'
    androidTestCompile 'info.cukes:cucumber-picocontainer:1.2.0'
    androidTestCompile 'info.cukes:gherkin:2.12.2'
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile files('libs/cucumber-android-1.2.1-SNAPSHOT.jar')


The cucumber tests are stored in a assets/features folder. I placed them under androidTest folder:


Then updated build.gradle with assets.srcDirs for androidTest:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId ""
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

        testApplicationId ""
        testInstrumentationRunner ""
    sourceSets {
        androidTest {
            assets.srcDirs = ['src/androidTest/assets']

At this point the project should build with no errors.

Test Code

The actual tests code is described here:
and in the project examples.

There are two things required by cucumber-jvm: the tests code should be in the same package as the test packageId, and the test runner should be Therefore, I've added these two lines to the defaultConfig part of the build.gradle:

 testApplicationId ""
 testInstrumentationRunner ""

Test Run Configuration

In order to create a new test run configuration for cucumber tests in Android Studio, select

Run > Edit Configurations
Click + and Select Android Tests
- Test name: CalculatorTest
- Module: app
- Specific instrumentation runner:
Click Ok

If you like, you can  run the tests from a command line:

cd your_project_folder
./gradlew connectedCheck

Test Run Results

The test results are displayed in the Android Studio:


thanks man, now it works in my project ;)

Popular posts from this blog

Using FlexUnit for Stress Testing

I saw quite a few questions in the forums on how to stress
test a Flex application. I thought about it and came up with an idea
that I want to share here.

I think FlexUnit can be used for stress testing. It is not
that difficult. I simply add multiple test runners for each client
application and run all of them asynchronously. Here is the example of
the FlexUnit runner:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" xmlns="*"

import flexunit.framework.TestSuite;
import test.TemperatureConverterTest;
import test.ArrayUtilTest;
import mx.collections.ArrayCollection;
import flexunit.flexui.TestRunnerBase;

public var testClients:ArrayCollection;

public var NUMBER_OF_TESTS:int = 100;

private function onCreationComplete():void
var cli…

Building a Flex project with Ant

Here is a quick sample on how to build a simple Flex
"hello world" project with Ant. The "hello world" project contains a src folder with one Flex application file and an Ant build.xml file:


The app.mxml is the main module of the project. It simply has a label with a "Hello World!" text:<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
<mx:Label text="Hello World!"/>
Here is the build.xml source:
<?xml version="1.0"?>
<project name="fx_practice7" default="all">

<!-- Init the build process -->
<target name="init" unless="initialized">
<!-- Name of project and version -->
<property name="FLEX_HOME" location="/Users/mykola/java/flex"/>

<property na…