gpt4 book ai didi

使用 Cucumber 和 Espresso 进行 Android 自动测试

转载 作者:行者123 更新时间:2023-11-30 00:56:44 25 4
gpt4 key购买 nike

我有 Cucumber 的问题,我无法开始测试,我一直有同样的问题,并且不知道如何解决它。

当我运行测试时,我收到了这条消息:

Started running tests
Test running failed: Instrumentation run failed due to 'cucumber.runtime.CucumberException'
Empty test suite.

我的build.gradle

android {
....
sourceSets {
androidTest {
assets.srcDirs = ['src/androidTest/assets']
}
}
}
dependencies {...
//Testing
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('info.cukes:cucumber-android:1.2.4') {
exclude module: 'cucumber-jvm-deps'
exclude module: 'guava'
}
androidTestCompile 'info.cukes:cucumber-jvm-deps:1.0.3'

cucumber runner :

CucumberOptions(features = "features/Test.feature")
public class CucumberInstrumentationRunner extends MonitoringInstrumentation {

private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);

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

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

测试功能

Scenario: Пользователь пытается авторизоваться используя неверные логин и пароль
Given I've launched "com.example.activities.LoginActivity"
When User 'User@User.com' singIn with password 'wrongPassword'
Then Check message about incorrect password

和登录 Activity 步骤

public class LoginActivitySteps extends InstrumentationTestCase {

// ViewInteractions

private final ViewInteraction mEmailEdt = onView(withId(R.id.edt_email));
private final ViewInteraction mPassEdt = onView(withId(R.id.edt_pass));
private final ViewInteraction mLoginBtn = onView(withId(R.id.button_login));

private Activity currentActivity;

@Given("^I've launched \"([^\"]*)\"$")

public void I_ve_launched_(String activityClassName)
throws Throwable {
String targetPackage = getInstrumentation().getTargetContext().getPackageName();
Class<? extends Activity> activityClass =
(Class<? extends Activity>) Class.forName(activityClassName);

currentActivity = launchActivity(targetPackage, activityClass, null);
}

@When("^User '(.+)' singIn with password '(.+)'$")
public void userLogin(String login, String password) {
mEmailEdt.perform(clearText());
mPassEdt.perform(clearText());
mEmailEdt.perform(ViewActions.typeText(login));
mPassEdt.perform(ViewActions.typeText(password));
mLoginBtn.perform(ViewActions.click());
}

@Then("^Check message about incorrect password")
public void checkTextOnScreen() {
onView(withText("Wrong pass")).check(matches(isDisplayed()));

}

最佳答案

我认为您缺少一些 build.gradle 配置部分,例如:

    testApplicationId "cucumber.cukeulator.test"
testInstrumentationRunner "cucumber.cukeulator.test.Instrumentation"

检查这个Cucumber示例build.gradle配置内容:https://github.com/cucumber/cucumber-jvm/blob/master/examples/android/android-studio/Cukeulator/app/build.gradle

希望对你有帮助

关于使用 Cucumber 和 Espresso 进行 Android 自动测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40018910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com