NullPointer Exception when using Espresso

前端 未结 5 998
孤独总比滥情好
孤独总比滥情好 2021-01-19 16:58

I\'m trying to use Espresso. But I got this error and I have no if I\'m missing some codes.

any thoughts will be highly appreciated.

error log:



        
5条回答
  •  醉话见心
    2021-01-19 17:42

    To clarify the instructions on https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions, referenced by @ValeraZakharov

    When using Android Studio and gradle, there is no need to update AndroidManifest.xml, instead the file build.gradle needs to be edited. Add this entry to the section android - defaultConfig:

    android {
        defaultConfig {
            testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
        }
    }
    

    Also: Right-click "add as a library" has been removed from Android studio, and replaced with:

    android {
        sourceSets {
            // Espresso instrumentation tests
            androidTest.setRoot('src/instrumentTest')
        }
    }
    

    The complete section android looks like this in my project:

    android {
        compileSdkVersion 17
        buildToolsVersion "19.0.1"
    
        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 16
            versionName getCommitNumber()
            testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
        }
    
        sourceSets {
            // Espresso instrumentation tests
            androidTest.setRoot('src/instrumentTest')
        }
    
        packagingOptions {
            // Multiple LICENSE.txt in hamcrest packages.
            exclude 'LICENSE.txt'
        }
    
    }
    

提交回复
热议问题