我想进行黄瓜测试。我无法调用或运行这些测试。这就是我所做的:
在app/build.gradle
defaultConfig {
testApplicationId "com.my.app.test"
testInstrumentationRunner "com.my.app.test.CucumberInstrumentation"
}
sourceSets {
androidTest { assets.srcDirs = ['src/androidTest/assets'] }
}
buildTypes {
debug {
testCoverageEnabled true
buildConfigField "String", "TEST_TAGS", "\"${getTestTags()}\""
}
}
def getTestTags() {
return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}
dependencies {
androidTestImplementation 'info.cukes:cucumber-android:1.2.5'
androidTestImplementation 'info.cukes:cucumber-picocontainer:1.2.5'
}
这是我在src/androidTest/assets/features
目录下的功能文件。
功能:输入登录详细信息
@login-feature
Scenario Outline: Successful Login
Given App is launch and user is not logged in
When I Click on Log in with Email button
And Login screen is launched
And I input an email, "<Email>"
And I input a password, "<Password>"
And I press on Log in button
Then I Should get logged in and redirect to home screen
Examples:
| Email | Password |
| user@login.com | mypasword123 |
这是我的StepDefinitions
目录下的登录src/androidTest/java/com/my/app/test
文件。
class LoginStepdefs {
@Rule
private ActivityTestRule<LoginActivity> activityTestRule = new ActivityTestRule<>(LoginActivity.class);
private LoginActivity activity;
@Before("@login-feature")
public void setUp() {
activityTestRule.launchActivity(new Intent());
activity = activityTestRule.getActivity();
}
@After("@login-feature")
public void tearDown() {
activityTestRule.getActivity().finish();
}
@Given("^App is launch and user is not logged in$")
public void appIsLaunchAndUserIsNotLoggedIn() throws Throwable {
System.out.println("appIsLaunchAndUserIsNotLoggedIn");
}
// and other functions
}
然后这是我的Runner文件。
@CucumberOptions(
features = "features",
glue = "com.my.app.test")
public class CucumberInstrumentation extends MonitoringInstrumentation {
private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);
@Override
public void onCreate(Bundle arguments) {
super.onCreate(arguments);
String tags = BuildConfig.TEST_TAGS;
if (!tags.isEmpty()) {
arguments.putString("tags", tags.replaceAll(",", "--").replaceAll("\\s",""));
}
instrumentationCore.create(arguments);
start();
}
@Override
public void onStart() {
super.onStart();
waitForIdleSync();
instrumentationCore.start();
}
}
并在AndroidManifest文件下。我添加了这个
<application
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="cucumber.api.android.CucumberInstrumentation"
android:targetPackage="com.my.app.test" />
现在,我正在尝试像这样使用Android Studio运行黄瓜测试:
因此,这是控制台输出。我还通过使用断点来检查它,调试器从不停止。
Testing started at 6:24 PM ...
02/12 18:24:35: Launching CucumberTests
$ adb push /home/sajid/Git/app-android/app/build/outputs/apk/debug/app-debug.apk /data/local/tmp/com.my.app
$ adb shell pm install -t -r "/data/local/tmp/com.my.app"
pkg: /data/local/tmp/com.my.app
Success
APK installed in 2 s 118 ms
$ adb push /home/sajid/Git/app-android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk /data/local/tmp/com.my.app.test
$ adb shell pm install -t -r "/data/local/tmp/com.my.app.test"
pkg: /data/local/tmp/com.my.app.test
Success
APK installed in 738 ms
Running tests
$ adb shell am instrument -w -r -e debug false com.my.app.test/com.my.app.test.CucumberInstrumentation
Client not ready yet..
Started running tests
Tests ran to completion.
Test running failed: Unable to find instrumentation info for: ComponentInfo{com.my.app.test/cucumber.api.android.CucumberInstrumentation}
Empty test suite.
请指导我哪里出了问题以及完成这项工作所需的条件。
答案 0 :(得分:0)
编辑:
您的Manifest
应该是这样的
<application
android:allowBackup="true"
android:label="@string/app_name">
<activity
android:name=".LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Obs:如果放入Gradle,则无需在此处放置仪器。
OLD :
检查文件“ CucumberInstrumentation”的“包”路径
com.my.app.test
之类的东西
复制此路径并将其粘贴到您的app/build.gradle
上。更改您的真实路径的com.my.app.test
,例如com.sajid.app.test
答案 1 :(得分:0)
我不知道是什么原因。但是在我的功能文件中
当我将“方案大纲:”更改为“方案:”
它开始工作