android - 由于 'Process crashed.',检测运行失败

标签 android testing 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());
    }
}

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

$ 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.

我不知道为什么它不起作用。

这是我的 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'

有什么建议吗?

最佳答案

自己找到了解决方案。 我更新到 AndroidX,因此我还需要从以下位置更新我的 build.gradle 文件:

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

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

关于android - 由于 'Process crashed.',检测运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52605267/

相关文章:

java - listItem 的缩放动画

java - Android Dialog 一直坐立不安 - 不会保持一种尺寸

testing - 任何 Haskell 测试框架中是否有 assertException?

ruby-on-rails - Rails factory_girl create_list 构建同一个对象

automated-tests - 在 Cypress 中如何计算包含文本的元素?

java - 如何测试 spring check_token 端点

android - 编辑文本错误 : content duplicates after pressing a restricted character

testing - 我可以对 ELisp 函数进行文档测试吗?

c# - 如何让 VS2013 中的 CodeMap 针对 SQL Server 2014 Express 实例运行?

java - 在垂直recyclerview中创建水平recyclerview,就像google play store with volley一样