java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/internal/runner/listener/InstrumentationRunListener

Viewed 365

I got following error when i executed my Unit Test code.

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/internal/runner/listener/InstrumentationRunListener;

My Unit Test code as following

@RunWith(AndroidJUnit4::class)
@LargeTest
class TestHomePageFragment {

 /*   @get:Rule
    var activityRule: ActivityTestRule<AudioPlayerActivity>
            = ActivityTestRule(AudioPlayerActivity::class.java)*/

    @Before
    fun setup(){

        val appContext: Context = InstrumentationRegistry.getInstrumentation().context
        val intent = Intent(appContext, AudioPlayerActivity::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        intent.putExtra(HomePageArouterConstants.KEY_ID,"1")
        val activityTestRule: ActivityTestRule<AudioPlayerActivity> = ActivityTestRule<AudioPlayerActivity>(AudioPlayerActivity::class.java, false, false)
        activityTestRule.launchActivity(intent)
    }



    @Test
    fun testVote(){
        onView(withId(R.id.linear_layout_like)).perform(click())
    }

}

The Build.gradle file

android {
    defaultConfig {
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
}


    dependencies {
    
    //    androidTestImplementation "androidx.test:core:$rootProject.testCoreVersion"
        androidTestImplementation rootProject.ext.dependencies["test-core"]
    //    androidTestImplementation "androidx.test:runner:$rootProject.testRunnerVersion"
        androidTestImplementation rootProject.ext.dependencies["test-runner"]
    //    androidTestImplementation "androidx.test:rules:$rootProject.testRulesVersion"
        androidTestImplementation rootProject.ext.dependencies["test-rules"]
    
    //    androidTestImplementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
        androidTestImplementation rootProject.ext.dependencies["androidx-appcompat"]
    //    androidTestImplementation "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion"
        androidTestImplementation rootProject.ext.dependencies["recyclerview"]
    //    androidTestImplementation "com.google.android.material:material:$rootProject.materialVersion"
        androidTestImplementation rootProject.ext.dependencies["material"]
    
    //    androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"
        androidTestImplementation rootProject.ext.dependencies["espresso-core"]
    //    androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion"
        androidTestImplementation rootProject.ext.dependencies["espresso-contrib"]
    //    androidTestImplementation "androidx.test.espresso:espresso-intents:$rootProject.espressoVersion"
        androidTestImplementation rootProject.ext.dependencies["espresso-intents"]
    //    androidTestImplementation "androidx.test.ext:junit:$rootProject.testExtJunit"
        androidTestImplementation rootProject.ext.dependencies["test-junit"]
    //    androidTestImplementation "androidx.test.uiautomator:uiautomator:$rootProject.uiAutomatorVersion"
        androidTestImplementation rootProject.ext.dependencies["test-uiautomator"]
    //    androidTestImplementation "androidx.work:work-testing:$rootProject.workVersion"
        androidTestImplementation rootProject.ext.dependencies["work-testing"]
    
    //    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
        androidTestImplementation   rootProject.ext.dependencies["core-testing"]
    //    androidTestImplementation "org.mockito:mockito-core:$rootProject.mockitoVersion"
        androidTestImplementation rootProject.ext.dependencies["mockito-core"]
    //    androidTestImplementation "org.mockito:mockito-android:$rootProject.mockitoAndroidVersion"
        androidTestImplementation rootProject.ext.dependencies["mockito-android"]
    
    }

I have Google for it, but none of answers can sort it out. Any ideas for this problem?

0 Answers
Related