问题描述
我已经创建了一个长者preSSO / UIAutomator单元测试。然而,当我尝试运行它,Android的Studio将无法识别它。选择TestLogin.java的按钮是灰色。我使用的Android 2.0工作室preVIEW 5.
I have created an Espresso/UIAutomator unit test. However, when I try to run it, Android Studio won't recognize it. The button to select TestLogin.java is greyed out. I'm using Android Studio 2.0 preview 5.
package com.greenrobot.yesorno.test.TestLogin
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit1.runner.RunWith;
import android.support.test.espresso.*;
/**
* Created by andytriboletti on 1/15/16.
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class TestLogin extends ActivityInstrumentationTestCase2<StartActivity> {
public TestLogin(Class<StartActivity> activityClass) {
super(activityClass);
}
private UiDevice mDevice;
@Rule
public ActivityTestRule<Home> mActivityRule = new ActivityTestRule(Home.class);
@Test
public void testLogin() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Start from the home screen
mDevice.pressHome();
onView(withText("Hello world!")).check(matches(isDisplayed()));
onView(withId(R.id.changeTextBt)).perform(click());
}
我的build.gradle:
My build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
aaptOptions.setProperty("cruncherEnabled", false)
sourceSets {
androidTest {
java.srcDirs = ['androidTest/java']
}
}
lintOptions {
// set to true to turn off analysis progress reporting by lint
quiet true
// if true, stop the gradle build if errors are found
abortOnError false
// if true, only report errors
ignoreWarnings true
}
productFlavors {
// The actual application flavor
production {
minSdkVersion 15
}
// Test application flavor for uiautomatior tests
myTest {
minSdkVersion 18
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.greenrobot.yesorno"
minSdkVersion 15
targetSdkVersion 22
multiDexEnabled = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
repositories {
maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
}
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
}
dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:multidex:1.0.1'
compile 'com.robbypond:mopub-android-sdk:3.9.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.jeremyfeinstein.slidingmenu:library:1.3@aar'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/FlurryAgent.jar')
compile files('libs/autobahn-android-0.5.2-SNAPSHOT.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile project(':viewpagerindicator')
compile files('libs/gcm.jar')
compile 'com.jakewharton.timber:timber:3.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.0.0'
}
编辑:这是我的Android工作室的照片。
EDIT2:启用所有的测试工件(单元测试和仪表测试)已经启用。
Enable all test artifacts (Unit Testing and Instrumentation Test) is already enabled.
推荐答案
我雇上Upwork开发人员寻找到这对我来说。主要的问题是在我的androidTest SRC指令被失踪SRC
I hired a developer on Upwork to look into this for me. The main problem was the my androidTest src directive was missing a 'src'
androidTest {
java.srcDirs = ['src/androidTest/java']
}
我的build.gradle:
My build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
aaptOptions.setProperty("cruncherEnabled", false)
sourceSets {
androidTest {
java.srcDirs = ['src/androidTest/java']
}
}
lintOptions {
// set to true to turn off analysis progress reporting by lint
quiet true
// if true, stop the gradle build if errors are found
abortOnError false
// if true, only report errors
ignoreWarnings true
}
productFlavors {
// The actual application flavor
production {
minSdkVersion 15
}
// Test application flavor for uiautomatior tests
myTest {
minSdkVersion 18
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.greenrobot.yesorno"
minSdkVersion 15
targetSdkVersion 22
multiDexEnabled = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
repositories {
maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
}
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
def autobahn_version = '0.5.2-SNAPSHOT'
dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:multidex:1.0.1'
compile 'com.robbypond:mopub-android-sdk:3.9.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.jeremyfeinstein.slidingmenu:library:1.3@aar'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/FlurryAgent.jar')
//compile files('libs/autobahn-android-0.5.2-SNAPSHOT.jar')
compile 'de.tavendo:autobahn-android:' + autobahn_version
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile project(':viewpagerindicator')
compile files('libs/gcm.jar')
compile 'com.jakewharton.timber:timber:3.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.0.0'
androidTestCompile 'junit:junit:4.12'
}
我TestLogin.java
My TestLogin.java
package com.greenrobot.yesorno.test;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.Until;
import android.test.suitebuilder.annotation.LargeTest;
import com.greenrobot.yesorno.Home;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import com.greenrobot.yesorno.R;
/**
* Created by andytriboletti on 1/15/16.
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class TestLogin {
private UiDevice mDevice;
private static final String PACKAGE_NAME = "com.greenrobot.yesorno";
private static final int LAUNCH_TIMEOUT = 5000;
@Rule
public ActivityTestRule<Home> mActivityRule = new ActivityTestRule(Home.class);
public TestLogin() {
super();
}
@Before
public void initTest() {
// Initialize UiDevice instance
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Start from the home screen
mDevice.pressHome();
// Wait for launcher
String launcherPackage = mDevice.getCurrentPackageName();
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
// Launch the app
Context context = InstrumentationRegistry.getContext();
Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
// Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)), LAUNCH_TIMEOUT);
}
@Test
public void testLogin() {
onView(withId(R.id.welcome)).check(matches(isDisplayed()));
// onView(withText("Hello world!")).check(matches(isDisplayed()));
//onView(withId(R.id.changeTextBt)).perform(click());
}
}
我花了10分钟试图让TESTLOGIN为code画幅,它不会工作,所以我创建了一个引擎收录。 #1,你应该让我来选择文件,然后将它们显示为$ C $角
I spent 10 minutes trying to get TestLogin to format as code and it wouldn't work so I created a pastebin. http://pastebin.com/9W3pT4rH Stackoverflow, you should allow me to select files, and then display them as code.
这篇关于不能选择编辑配置测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!