代码之家  ›  专栏  ›  技术社区  ›  Jono

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

  •  0
  • Jono  · 技术社区  · 6 年前

    嗨,我正试图在我的项目中运行示例工具化测试类,但每次运行时,我都会收到以下错误:

    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'
      }
    }
    
    1 回复  |  直到 6 年前
        1
  •  14
  •   Community CDub    6 年前

    将我的android studio更新到3.3版并删除

    testOptions {
        execution 'ANDROID_TEST_ORCHESTRATOR'
    }
    

    工作

        2
  •  4
  •   Bob Liberatore    5 年前

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

    execution 'ANDROID_TEST_ORCHESTRATOR'

    execution 'ANDROIDX_TEST_ORCHESTRATOR'