Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android测试运行失败:没有测试结果_Java_Android_Unit Testing_Junit_Kotlin - Fatal编程技术网

Java Android测试运行失败:没有测试结果

Java Android测试运行失败:没有测试结果,java,android,unit-testing,junit,kotlin,Java,Android,Unit Testing,Junit,Kotlin,您好,我试图在我的项目中运行示例插装测试类,但每次运行时都会出现以下错误: Test running failed: no test results Empty test suit 下面是我的示例intrumented测试类 import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith /** * Instrumented test, which will execute

您好,我试图在我的项目中运行示例插装测试类,但每次运行时都会出现以下错误:

Test running failed: no test results
Empty test suit
下面是我的示例intrumented测试类

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().context
        assertEquals("com.app", appContext.packageName)
    }
}
以下是我的gradle测试构建文件:

android {
  compileSdkVersion 28
    defaultConfig {
        applicationId "com.app"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments clearPackageData: 'true'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    testOptions {
        execution 'ANDROID_TEST_ORCHESTRATOR'
    }
}

dependencies {

    def mockito = "2.18.3"
//android instrumental test
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.ext:truth:1.1.0'
    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.arch.core:core-testing:2.0.0'
    androidTestUtil 'androidx.test:orchestrator:1.1.1'

    androidTestImplementation 'com.jraska.livedata:testing-ktx:0.6.0'
    androidTestImplementation 'com.jraska.livedata:testing:0.6.0'

    androidTestImplementation "org.mockito:mockito-core:$mockito"
    androidTestImplementation "org.mockito:mockito-android:$mockito"
    androidTestImplementation "org.mockito:mockito-inline:$mockito"

    androidTestImplementation 'org.koin:koin-test:1.0.2'

    //unit test
    testImplementation 'junit:junit:4.12'
    testImplementation "org.mockito:mockito-core:$mockito"
    testImplementation "org.mockito:mockito-android:$mockito"
    testImplementation "org.mockito:mockito-inline:$mockito"
    testImplementation 'org.koin:koin-test:1.0.2'
    testImplementation 'androidx.test.ext:junit:1.1.0'
    testImplementation 'androidx.arch.core:core-testing:2.0.0'
    testImplementation 'com.jraska.livedata:testing-ktx:0.6.0'
    testImplementation 'com.jraska.livedata:testing:0.6.0'
    testImplementation 'androidx.test.ext:truth:1.1.0'
  }
}

将我的Android Studio更新为3.3版并删除

testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
}

工作

除了测试编排器之外,您完全可以使用AndroidX进行测试。不是删除测试编排器(这非常有用),而是更改

execution'ANDROID\u TEST\u ORCHESTRATOR'


execution'ANDROIDX\u TEST\u ORCHESTRATOR'

我遇到了同样的问题,因为内容提供商的权限冲突,android studio无法安装apk。卸载apk成功了

您是如何运行的?只需在Studio中右键单击测试并单击运行。。。应该运行测试是的,我就是这样运行的。我注意到,我在androidTest资源文件夹中有mockito内联函数,当我摆脱它时,我得到了一个不同的错误,说mockito是操作系统相关的错误,mockito内联函数应该修复任何建议?仍然得到相同的错误这是最近Android Studio版本中kotlin测试的一个错误。请确保您已将Android Studio更新至最新版本,即目前的3.2.1版本。是否有大量跟踪日志?这也不工作,我手动做gradlew连接androidTestamazeballs-这是关键!为什么谷歌不在自己的设置中添加注释,因为这是早些时候需要的……这就是谷歌的原因。糟糕的文件这太荒谬了。在没有任何可读错误消息的情况下删除此gradle选项是必要的。有人能解释一下为什么这样做吗?只是出于好奇在我的案例中更新了androidx.test:orchestrator从1.1.0到1.2.0helped@Chisko有很多不同的方式会出现这种错误。我的答案是针对OP的gradle文件的。我建议你咨询官方文件,确保一切都设置正确:老兄,你认为我没有看过他们的文件吗?我的错误与OP的错误完全相同,而你的解决方案不起作用,即使我不想,我也不得不删除线路,现在浓缩咖啡起作用了。@Chisko你的错误相同并不意味着它们有相同的原因。我建议,如果这对您不起作用,那么请将您自己的问题与构建文件一起发布。@Robert Liberatore这是我的问题。我甚至没有注意到我没有使用ANDROIDX。谢谢