I have an Android application project that I want to add automated tests to. For this, I would like to use Cucumber for java in Android Studio and run these tests directly in my IDE (with Run / Debug configuration).
I am using Windows 7 sp1 64 bit using Android Studio 0.8.9. I added the plugins Gherkin version 134.1007 and Cucumber for Java version 134.1007. I use the following libraries for cucumber:
- cucumber android 1.1.8
- cucumber core-1.1.8
- Cucumber HTML-0.2.3
- cucumber-java-1.1.8
- cucumber JUnit-1.1.8
- Cucumber-JVM-Deps-1.0.3
- gherkins-2.12.2
- Robotium solo 5.2.1
This is my project structure:
TruckCalibrator/ .idea/ app/ build/ libs/ [libraries listed above in .jar format] src/ main/ java/ com/ novomnetworks/ formeval/ truckcalibrator/ MainActivity.java res/ AndroidManifest.xml test/ assets/ features/ app_start.feature java/ com/ novomnetworks/ formeval/ truckcalibrator/ test/ CucumberTest.java build.gradle build/ gradle/
This is my gradle file:
apply plugin: 'com.android.application' android { compileSdkVersion 20 buildToolsVersion '20.0.0' defaultConfig { applicationId "com.novomnetworks.formeval.truckcalibrator" minSdkVersion 16 targetSdkVersion 20 versionCode 1 versionName "1.0" testInstrumentationRunner "cucumber.api.android.CucumberInstrumentation" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { instrumentTest { java.srcDirs = ['src/test/java'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.github.satyan:sugar:1.3' }
This is my manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.novomnetworks.formeval.truckcalibrator" xmlns:tools="http://schemas.android.com/tools"> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.INTERNET" /> <instrumentation android:name="cucumber.api.android.CucumberInstrumentation" android:targetPackage="com.novomnetworks.formeval.truckcalibrator.test" /> <application android:allowBackup="true" android:icon="@drawable/launcher_icon" tools:replace="icon" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.orm.SugarApp"> <uses-library android:name="android.test.runner" /> <meta-data android:name="DATABASE" android:value="form-eval.db" /> <meta-data android:name="VERSION" android:value="1" /> <meta-data android:name="QUERY_LOG" android:value="true" /> <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.novomnetworks.formeval.truckcalibrator.database" /> <activity android:name=".MainActivity" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
This is my cucumber step description file ( CucumberTest.java ):
package com.novomnetworks.formeval.truckcalibrator.test; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; import cucumber.api.CucumberOptions; import cucumber.api.PendingException; import cucumber.api.java.After; import cucumber.api.java.Before; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import cucumber.api.junit.Cucumber; import com.novomnetworks.formeval.truckcalibrator.MainActivity; import com.novomnetworks.formeval.truckcalibrator.R; import com.robotium.solo.Solo; import org.junit.runner.RunWith; @RunWith(Cucumber.class) public class CucumberTest extends ActivityInstrumentationTestCase2<MainActivity> { private static final String TAG = "CucumberTest"; Solo solo; public CucumberTest() { super(MainActivity.class); } @Before protected void before() throws Exception { Log.d(TAG, "setUp"); super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); getActivity().resetDB(); } @After protected void after() throws Exception { Log.d(TAG, "tearDown"); solo.finishOpenedActivities(); super.tearDown(); } @Given("^I started the app$") public void i_started_the_app() throws Throwable { solo.waitForActivity(MainActivity.class); throw new PendingException(); } @Then("I should see the action bar") public void I_should_see_the_action_bar() throws Exception { assertNotNull(getActivity().getMenu()); } @Given("I am on the clients list") public void I_am_on_the_clients_list() throws Exception { solo.waitForFragmentById(R.layout.fragment_clients); } @Then("^I should see the clients list header$") public void I_should_see_the_clients_list_header() throws Exception { assertTrue(solo.searchText(solo.getString(R.string.clients))); assertTrue(solo.searchText(solo.getString(R.string.sorted_by))); assertNotNull(solo.getView(R.id.clients_spinner)); } @Then("I should see the new client button") public void I_should_see_the_new_client_button() throws Exception { assertNotNull(solo.getView(R.id.action_new_client).isShown()); } @Then("^I should see the clients list$") public void I_should_see_the_clients_list() throws Exception { assertNotNull(solo.getView(R.id.clients)); } }
And this is my function file:
Feature: Dรฉmarrage de l'app Scenario: La barre de menu devrait s'afficher Given I started the app Then I should see the action bar Scenario: La liste des clients devrait s'afficher Given I started the app Then I should see the clients list header And I should see the new client button And I should see the clients list
When I run my Cucumber test configuration, (screenshot below)
Functions found, but my step definitions are not. The output is indicated
Undefined step: Given I started the app Undefined step: Then I should see the action bar Undefined step: Given I started the app Undefined step: Then I should see the clients list header Undefined step: And I should see the new client button Undefined step: And I should see the clients list 2 Scenarios (2 undefined) 6 Steps (6 undefined) 0m0,000s You can implement missing steps with the snippets below: @Given("^I started the app$") public void i_started_the_app() throws Throwable {
I searched the Internet all day without finding the right way to link the step definition file. Every mail I find seems to be telling people to mention the test package in the Glue configuration field, and this is what I did, but it is useless. If you look closely at my CucumberTest.java file, you will see that I tried using the @CucumberOptions annotation, but that did not change the result. I also tried with the @RunWith(Cucumber.class) annotation @RunWith(Cucumber.class) and without it.
What am I doing wrong?