vendredi 22 février 2019

Android + Cucumber = Test running failed

I just created a simple Android app and a basic Gherkin feature file.

Here is my build.gralde:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "fr.guddy.maxnumberapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 'fr.guddy.maxnumberapplication.test.e2e.CucumberInstrumentation'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        androidTest {
            assets.srcDirs = ['src/androidTest/assets']
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation group: 'com.android.support', name: 'design', version: '28.0.0'

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    androidTestImplementation group: 'io.cucumber', name: 'cucumber-java', version: '4.2.3'
    androidTestImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '4.2.3'
    androidTestImplementation group: 'io.cucumber', name: 'cucumber-android', version: '4.2.2'
    androidTestImplementation group: 'io.cucumber', name: 'cucumber-picocontainer', version: '4.2.3'
}

I defined my feature in app/src/androidTest/assets/features and a class with the given/when/then steps.

I defined an instrumentation:

package fr.guddy.maxnumberapplication.test.e2e;

@CucumberOptions(
        features = "features"
)
public final class CucumberInstrumentation extends AndroidJUnitRunner {
    private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);

    @Override
    public void onCreate(final Bundle arguments) {
        super.onCreate(arguments);
        instrumentationCore.create(arguments);
        start();
    }

    @Override
    public void onStart() {
        super.onStart();
        waitForIdleSync();
        instrumentationCore.start();
    }
}

And I have also a runner:

package fr.guddy.maxnumberapplication.test.e2e;

@RunWith(Cucumber.class)
@CucumberOptions(
        glue = "fr.guddy.maxnumberapplication.e2e.steps",
        features = "features"
)
public class CucumberRunner {
}

And here is what I get when running either the run or the gralde connectedCheck task:

$ adb shell am instrument -w -r   -e debug false -e class 'fr.guddy.maxnumberapplication.test.e2e.CucumberRunner' fr.guddy.maxnumberapplication.test/fr.guddy.maxnumberapplication.test.e2e.CucumberInstrumentation
Client not ready yet..
Started running tests
Test running failed: Instrumentation run failed due to 'Process crashed.'
Empty test suite.

and :

No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

Can you help figure out what's the problem and why it doesn't run my tests? Maybe you can see where I'm wrong and what part of the configuration is duplicated.

Thanks in advance.

Regards.

Aucun commentaire:

Enregistrer un commentaire