为什么官方文档中的Android Instrumented Test示例不起作用()

业无高卑志当坚,男儿有求安得闲?这篇文章主要讲述为什么官方文档中的Android Instrumented Test示例不起作用?相关的知识,希望能为你提供帮助。
在https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests上的文档之后,我为我的app模块创建了以下build.gradle文件:

buildscript { repositories { mavenCentral() maven { url 'https://maven.fabric.io/public' } }dependencies { classpath 'io.fabric.tools:gradle:1.25.3' } } apply plugin: 'com.android.application' apply plugin: 'io.fabric'repositories { maven { url 'https://maven.fabric.io/public' } }android {compileSdkVersion 27 buildToolsVersion '27.0.3' useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "com.myapp" minSdkVersion 19 targetSdkVersion 19 versionCode 7 versionName "1.3.0" ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" }testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }sourceSets { main { jniLibs.srcDirs = ['libs'] } } lintOptions { checkReleaseBuilds false abortOnError false } dexOptions { javaMaxHeapSize "4g" } }dependencies { // Required -- JUnit 4 framework testImplementation 'junit:junit:4.12' // Optional -- Mockito framework testImplementation 'org.mockito:mockito-core:1.10.19' androidTestImplementation 'com.android.support:support-annotations:27.1.1' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:rules:1.0.2' androidTestImplementation 'org.hamcrest:hamcrest-library:1.3' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-accessibility:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.2' androidTestImplementation 'com.android.support.test.espresso.idling:idling-concurrent:3.0.2'implementation fileTree(include: ['*.jar'], dir: 'libs') implementation project(':deviceprint-lib-2.0.1') implementation files('libs/gson-2.2.4.jar') implementation files('libs/activation.jar') implementation files('libs/additionnal.jar') implementation files('libs/mail.jar')implementation 'com.android.support:support-v4:27.1.1'}

和以下项目级build.gradle:
buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' } }allprojects { repositories { jcenter() google() } }

我在app / src / androidTest / java / com / mypackage创建了一个目录并添加了以下文件:
package com.mypackage; import android.support.test.runner.AndroidJUnit4; import org.junit.Test; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; public class ApplicationTest { public ApplicationTest() {}@Test public void failingTest() { assertThat(false, is(true)); } }

所有的import语句和@Test注释都被标记为错误,并显示消息“无法解析符号”,如果我在项目窗口中右键单击该文件,则无法选择“运行”。为什么?
答案【为什么官方文档中的Android Instrumented Test示例不起作用()】重新启动Android Studio后,该示例开始正常运行。 :捂脸:
编辑:另一个注释,因为我最近经历了这些相同的症状有不同的原因:构建变体必须设置为“debug”(或者你必须在模块的testBuildType文件的android {}块内设置build.gradle到你想要测试的变体)

    推荐阅读