由于"进程崩溃",仪表运行失败.

gur*_*gui 22 testing android automated-tests

我想运行以下测试:

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());
    }
}
Run Code Online (Sandbox Code Playgroud)

但我在控制台中收到错误:

$ 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.
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么它不起作用.

这是我的gradle文件:

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'
Run Code Online (Sandbox Code Playgroud)

有什么建议?

gur*_*gui 53

我自己找到了解决方案.我更新到AndroidX,因此我还需要将我的gradle文件从:testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"更新到testInstrumentationRunner"androidx.test.runner.AndroidJUnitRunner"

  • 我的Android Studio自动更新为**androidx.test.runner.AndroidJUnitRunner**,还是有这个问题 (16认同)
  • 我正在使用自定义 JUnitRunner 并面临这个问题。我已经验证包名称是正确的。我不知道还能做什么 (2认同)
  • 这里与@AdamMc331 相同.. 我有一个自定义的 JUnitRunner,有时测试通过,在某些情况下会失败。有时它在测试通过后崩溃,有时一起崩溃。这真的很令人沮丧。 (2认同)

小智 9

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"
Run Code Online (Sandbox Code Playgroud)

除了 androidx.test.runner.AndroidJunitRunner 配置外,还请检查依赖关系。上面的代码对我有用。


chi*_*nce 6

我错了:

Test running failed: Instrumentation run failed due to 'Process crashed.'
Run Code Online (Sandbox Code Playgroud)

就我而言,Android测试控制台仅显示以上错误,没有任何详细信息

但是,在logcat中,它显示了err详细信息,就我而言,这是因为我忘记在AndroidManifest.xml中添加admob app_id

所以

有关错误的详细信息,请参见logcat

有关错误的详细信息,请参见logcat

有关错误的详细信息,请参见logcat

  • 这节省了我花几个小时研究这个问题的时间。Logcat 获胜 (4认同)
  • 当它说检查 logcat 然后 logcat 时 (3认同)

mus*_*unk 5

所以我有相同的症状,但在进行所有这些更改后,我发现我的项目 build.gradle 文件中的以下配置是一个问题

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

似乎 minifyEnable 和 ShrinkResources 在升级到 androidx 后表现不同,可能更早发生,但我现在才意识到。注释掉这些行修复了我的“未发现测试”问题。

buildTypes{
     debug {
        debuggable true
        //minifyEnabled true
        //shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
Run Code Online (Sandbox Code Playgroud)