Android + Cucumber =测试运行失败

时间:2019-02-22 17:39:30

标签: android testing cucumber

我刚刚创建了一个简单的Android应用和一个基本的Gherkin功能文件。

这是我的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'
}

我在app/src/androidTest/assets/features中定义了我的功能,并定义了一个具有给定/何时/然后步骤的类。

我定义了一种检测手段:

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();
    }
}

我还有一个跑步者:

package fr.guddy.maxnumberapplication.test.e2e;

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

这是运行run或gralde connectedCheck任务时得到的结果:

$ 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.

和:

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).

您能帮忙找出问题所在,为什么它不能运行我的测试? 也许您可以看到我错了,以及配置的哪一部分重复了。

谢谢。

致谢。

0 个答案:

没有答案