6

I have been trying to run a test case , present in androidTest Package. But as i execute the test, Emulator launches and I get tests passed : 0 Passed.

and getting this Error in logcat

E/AndroidJUnitRunner: An unhandled exception was thrown by the app.


E/InstrumentationResultPrinter: Failed to mark test No Tests as finished after process crash

here is my code.

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
class MyAndroidTest {

    @Test
     fun test_simple() {
        assertEquals(2, 1+1)
    }
}

I have added all required dependencies.

testImplementation 'junit:junit:4.12'
androidTestImplementation 'junit:junit:4.12'

testImplementation "androidx.test.ext:junit-ktx:1.1.3"
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.3"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

testImplementation "org.robolectric:robolectric:4.6"

testImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation "com.google.truth:truth:1.1.3"


testImplementation 'org.mockito:mockito-core:2.24.5'
// required if you want to use Mockito for Android tests
androidTestImplementation 'org.mockito:mockito-android:2.24.5'

When I run the same test case in test package, it runs successfully. One thing is, I created The androidTest package by myself. It was somehow deleted earlier..

I get this after I run the test case,

enter image description here enter image description here

plz help.

Roop Kishore
  • 199
  • 1
  • 11
  • See also https://stackoverflow.com/questions/72114551/android-studio-testing-shows-test-results-0-0-how-can-i-begin-the-tests. – CoolMind Jan 11 '23 at 07:07

1 Answers1

2

Add testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" in defaultConfig block inside gradle module file

Is missing in that project and it's necessary.

NullPointerException
  • 36,107
  • 79
  • 222
  • 382