75

I wanted to run the following test:

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());
    }
}

But I get the error in the console:

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

I can not figgure out why its not working.

Here is my gradle file:

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'

Any suggestions?

gurehbgui
  • 14,236
  • 32
  • 106
  • 178

10 Answers10

115

Found the solution by myself. I updated to AndroidX, therefor I needed also to update my build.gradle file from:

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

to

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
gurehbgui
  • 14,236
  • 32
  • 106
  • 178
  • 1
    For me it was the other way. I was not using AndroidX, but had the runner set to androidx.test." – Ajith M A Dec 10 '18 at 16:41
  • 27
    My Android Studio updated automatically to **androidx.test.runner.AndroidJUnitRunner**, and still having this problem – IgorGanapolsky Jan 06 '19 at 15:39
  • 3
    I'm using a custom JUnitRunner and facing this problem. I've verified that the package name is correct. I don't know what else to do – AdamMc331 Jan 31 '19 at 15:13
  • 2
    Same here as @AdamMc331 .. I have a custom JUnitRunner and sometimes the test passes, on some occasions, it fails. Sometimes it crashes after test passes, sometimes all together. It's really frustrating. – tsaulic Feb 27 '19 at 06:35
  • @AdamMc331 did you get this working with custom JUnitRunner? Having the same issue – Tys Jul 08 '19 at 21:34
  • 1
    @Tys I use a custom JUnitRunner successfully in this project: https://github.com/adammc331/pokedex I can't remember all the way back to what issue I was having, but maybe by comparing the code you'll see something that sticks out. – AdamMc331 Jul 08 '19 at 21:54
  • I am using - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" still its facing. – arango_86 Jan 19 '21 at 13:02
88

I got the error:

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

In my case, the android test console only showed the error above without any details.

But in the logcat, the full error was shown. In my case, I forgot to add the AdMob app_id in AndroidManifest.xml

So always remember to check the logcat for more error details!

laim2003
  • 299
  • 4
  • 19
chikadance
  • 3,591
  • 4
  • 41
  • 73
  • The problem is my logcat has 100 of logged stuff, I'm being unable to find the right log location – David Jul 05 '20 at 23:37
  • Well over a year later and this saved me days of pulling my hair out, I'm using androidx.startup and for some strange reason It needs to be part of my androidTestImplementation otherwise my instrumented tests fail since it's missing from the .test class path :) Thank you! – wax911 Sep 26 '20 at 19:09
7
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"

except for the androidx.test.runner.AndroidJunitRunner config, please also check the dependency. The above code worked for me.

kingston
  • 11,053
  • 14
  • 62
  • 116
XccX
  • 71
  • 1
  • 2
  • ```androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"``` was specifically the one causing the error for me :) – klenki Feb 08 '21 at 08:15
5

So I had the same symptoms but after making all these changes I found that the following config in my project build.gradle file that was an issue

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

seems that minifyEnable and shrinkResources are behaving differently after the upgrade to androidx, could have happened earlier but I just realized it now. Commenting out the lines fixed my No Tests Found Issues.

buildTypes{
     debug {
        debuggable true
        //minifyEnabled true
        //shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
musterjunk
  • 341
  • 3
  • 15
3

I got the same error after updating JUnit4 from:

androidTestImplementation 'junit:junit:4.12

to

androidTestImplementation 'junit:junit:4.13

The error went away when I downgraded back to:

androidTestImplementation 'junit:junit:4.12
Izzy Stannett
  • 242
  • 1
  • 11
1

Generally you'd want the whole suite to match at once: https://developer.android.com/jetpack/androidx/releases/test

So for example, the latest as of writing is

Core 1.4.0
Espresso 3.4.0
Intents 3.4.0
JUnit 1.1.3
Monitor 1.4.0
Orchestrator 1.4.0
Runner 1.4.0
Rules 1.4.0
Truth 1.4.0
Test Services 1.4.0
Muz
  • 5,866
  • 3
  • 47
  • 65
1

I was getting this error while trying to debug an AndroidJUnit4 test. Run Test worked but Debug Test was throwing this error. I read that it may be related to this issue. I resolved this error by going to "Edit Configurations" on Android Studio, then "All Tests", Select "Debugger" and set to "Java Only".

DrMaxB
  • 540
  • 1
  • 3
  • 13
0

This error appeared because I changed testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" to testInstrumentationRunner "androidx.test.ext.junit.runners.AndroidJUnit4" in build.gradle. In LogCat I saw:

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 ...
CoolMind
  • 26,736
  • 15
  • 188
  • 224
0

For me, I was working with runtime permission and revoking the permission (tried adb commands and uiAutomation.revokeRuntimePermission) caused this issue, as an alternate approach, I used Android Test Orchestrator, that seems to be working great so far.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
0

When I checked logcat, in my case it was OOM so I increased my emulator's heap and RAM size generously and it worked like a charm.

prateek
  • 440
  • 4
  • 12