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

由于“进程崩溃”,检测运行失败

  •  11
  • gurehbgui  · 技术社区  · 6 年前

    我想运行以下测试:

    package com.xxx.yyy;
    
    import android.content.Context;
    import androidx.test.InstrumentationRegistry;
    import androidx.test.runner.AndroidJUnit4;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import static org.junit.Assert.*;
    
    /**
     * Instrumented test, which will execute on an Android device.
     *
     * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
     */
    @RunWith(AndroidJUnit4.class)
    public class ExampleInstrumentedTest {
        @Test
        public void useAppContext() {
            // Context of the app under test.
            Context appContext = InstrumentationRegistry.getTargetContext();
    
            assertEquals("com.xxx.yyy", appContext.getPackageName());
        }
    }
    

    $ adb shell am instrument -w -r   -e debug false -e class 'com.xxx.yyy.ExampleInstrumentedTest' com.xxx.yyy.test/android.support.test.runner.AndroidJUnitRunner
    Client not ready yet..
    Started running tests
    Test running failed: Instrumentation run failed due to 'Process crashed.'
    Empty test suite.
    

    我弄不明白为什么它不起作用。

    这是我的毕业档案:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    
    apply plugin: 'org.greenrobot.greendao' // das kann dann später weg
    //apply plugin: 'kotlin-kapt' // if using Kotlin
    //apply plugin: 'io.objectbox'
    
    
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.xxx.yyy"
            minSdkVersion 21
            targetSdkVersion 28    
            versionCode 130
            versionName "1.3.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    greendao {
        schemaVersion 4
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.0.0'
        implementation 'com.google.android.material:material:1.0.0'
        implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
        implementation 'org.greenrobot:greendao:3.2.2'
        implementation 'com.google.firebase:firebase-core:16.0.3'
        implementation 'com.google.firebase:firebase-ads:15.0.1'
        testImplementation 'junit:junit:4.12'
        implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test:rules:1.0.2'
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    有什么建议吗?

    2 回复  |  直到 6 年前
        1
  •  100
  •   Masoud Mokhtari Mehran Jafari    6 年前

    我更新了AndroidX,因此我也需要更新我的 build.gradle 文件来源:

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    
        2
  •  53
  •   laim2003    4 年前

    Test running failed: Instrumentation run failed due to 'Process crashed.'
    

    在我的例子中,android测试控制台只显示了上面的错误,没有任何细节。

    但是 在logcat中,显示了完整的错误。在我的例子中,我忘记在AndroidManifest.xml中添加AdMob app\u id

    所以一定要记得检查logcat以获得更多的错误细节!

        3
  •  4
  •   Boken forcewill    4 年前
    androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
    androidTestImplementation "androidx.test:runner:1.3.0"
    androidTestImplementation "androidx.test:core:1.3.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.2"
    androidTestImplementation "androidx.test:rules:1.3.0"
    

    除了androidx.test.runner.AndroidJunitRunner配置之外,还请检查依赖关系。上面的代码是为我工作。

        4
  •  3
  •   Izzy Stannett    5 年前

    在更新JUnit4之后,我遇到了相同的错误:

    androidTestImplementation 'junit:junit:4.12
    

    androidTestImplementation 'junit:junit:4.13
    

    当我降级回:

        5
  •  1
  •   musterjunk    5 年前

    所以我有同样的症状,但在做了所有这些更改之后,我发现project build.gradle文件中的以下配置有问题

    buildTypes{
         debug {
            debuggable true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    

    buildTypes{
         debug {
            debuggable true
            //minifyEnabled true
            //shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    
        6
  •  0
  •   CoolMind    4 年前

    出现此错误是因为我更改了 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.ext.junit.runners.AndroidJUnit4"

    java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.example.debug.test/androidx.test.ext.junit.runners.AndroidJUnit4}: java.lang.ClassNotFoundException: Didn't find class "androidx.test.ext.junit.runners.AndroidJUnit4" on path: DexPathList[[zip file ...