Question

I have been trying to integrate Cucumber(java) with Robotium to add BDD to android tests in the Android studio. Unfortunately i am getting stuck trying to run the Cucumber features as it is not able to identify the step definitions.

My folder structure is as below:

ParentProject

   |
   Module
      |
      src
        |
         instrumentTest
                | 
                java(this is the source root in build.gradle)
                   | 
                   cucumbertests
                        | 
                        CukeRunner.java
                        | 
                        steps
                |
                resources
                   |
                   cucumbertests
                         |
                         Sample.feature

The above setup works fine in intellij.

My build.gradle in the module is as follows:

    buildscript {
    dependencies {
        repositories {
            mavenCentral()
            mavenLocal()
        }
        classpath 'com.android.tools.build:gradle:0.7.3'
    }

}

apply plugin: 'android'

dependencies {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.android.support:appcompat-v7:19.0.0'
    compile 'com.google.android.gms:play-services:4.0.30'
    compile 'com.squareup:otto:1.3.4'
    compile 'com.squareup.dagger:dagger:1.1.0'
    compile 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.squareup.okhttp:okhttp:1.2.1'
    compile 'com.squareup.retrofit:retrofit:1.2.1'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:15.0'
    compile 'com.google.maps.android:android-maps-utils:0.2.1'
    compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    compile fileTree(dir: 'libs', include: '*.jar')

    instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
    instrumentTestCompile 'info.cukes:cucumber-android:1.1.5'
    instrumentTestCompile 'info.cukes:cucumber-junit:1.1.5'
    instrumentTestCompile 'info.cukes:cucumber-picocontainer:1.1.5'
    instrumentTestCompile 'info.cukes:gherkin:2.12.2'
}

android {

    testBuildType "debug"
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    signingConfigs {
        debug {
            storeFile file('../certificate/debug.keystore')
        }
    }

    sourceSets {
        instrumentTest {
            java.srcDirs = ['src/instrumentTest/java','src/instrumentTest/cucumber']
        }

        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'AndroidRSS/src']
            resources.srcDirs = ['src/main/res']
            aidl.srcDirs = ['src/main/aidl']
            renderscript.srcDirs = ['src/main/rs']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
    }
}

Error i get is that Cucumber hasnt been able to detect the step definitions. Since this structure works in intellij i think it may just be different way to be able to have this working in Android studio.

I am trying to have a test work like this https://stackoverflow.com/a/19940625/1165859

My feature file is :

enter image description here

The Feature file run config is :

enter image description here

The cukerunner is

    package cucumbertests;

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;



@RunWith(Cucumber.class)
@Cucumber.Options()
public class cukerunner {
}

Run results i get are:

enter image description here

Inspite of these methods implemented in the cucumbertests.steps

No correct solution

OTHER TIPS

It seems gradle tags are misplaced in build.gradle script file . Please look at below build.gradle file and do the necessary changes.

buildscript {

        repositories {
            mavenCentral() // This only tells gradle where the to find the android plugin
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.7.3'
        }

}

apply plugin: 'android'

repositories {
        mavenCentral()
        mavenLocal()
    }


dependencies {

    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.android.support:appcompat-v7:19.0.0'
    compile 'com.google.android.gms:play-services:4.0.30'
    compile 'com.squareup:otto:1.3.4'
    compile 'com.squareup.dagger:dagger:1.1.0'
    compile 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.squareup.okhttp:okhttp:1.2.1'
    compile 'com.squareup.retrofit:retrofit:1.2.1'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:15.0'
    compile 'com.google.maps.android:android-maps-utils:0.2.1'
    compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    compile fileTree(dir: 'libs', include: '*.jar')

    instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
    instrumentTestCompile 'info.cukes:cucumber-android:1.1.5'
    instrumentTestCompile 'info.cukes:cucumber-junit:1.1.5'
    instrumentTestCompile 'info.cukes:cucumber-picocontainer:1.1.5'
    instrumentTestCompile 'info.cukes:gherkin:2.12.2'
}

android {

    testBuildType "debug"
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    signingConfigs {
        debug {
            storeFile file('../certificate/debug.keystore')
        }
    }

    sourceSets {
        instrumentTest {
            java.srcDirs = ['src/instrumentTest/java','src/instrumentTest/cucumber']
        }

        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'AndroidRSS/src']
            resources.srcDirs = ['src/main/res']
            aidl.srcDirs = ['src/main/aidl']
            renderscript.srcDirs = ['src/main/rs']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
    }
}

What is there inside src/instrumentTest/cucumber directory. If you have any java classes there I think you have to move then in java directory of test project.

On cucumber github page there's a new implementation of how to use cucumber on Android Studio.

I've tested today and it worked

Check it out: https://github.com/cucumber/cucumber-jvm/tree/master/examples/android/android-studio/Cukeulator

I'll be glad to help if you have any doubts

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top