AndroidManifest.xml and tests in Android Studio

点点圈 提交于 2020-01-15 12:23:49

问题


I have a basic Android project with an application sources directory and tests sources directory set up by the Android Project template.

I have read that Android tests uses an Androidmanifest.xml specific to the running tests in which we have to specify the instrumentation type and the target package:

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.mypackage.app" />

In Android Studio,I can run tests with android tests configuration without specifiying an AndroidManifest.xml file specific to my tests (there is no AndroidManifest.xml file in my tests sources).

When I run tests in Android Studio I can see that my app is deployed before tests are running and then my tests are launched. Therefore, I guessed that Android Studio himself manage the test process and the generation of the AndroidManifest.xml specific to the tests.

Am I correct ?


回答1:


According to the docs for the Android Gradle plugin (http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing), when describing how to set up source sets for Android tests:

The sourceSet should not contain an AndroidManifest.xml as it is automatically generated.

You can configure parameters for the test such as the InstrumentationTestRunner directly fro the build file like so:

android {
    defaultConfig {
        testPackageName "com.test.foo"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testHandleProfiling true
        testFunctionalTest true
    }
}



回答2:


Because Android Gradle plugin update, on the basis of Scott Barta's answer, now you maybe write like this:

android {
    defaultConfig {
        testApplicationId "com.test.foo"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testHandleProfiling true
        testFunctionalTest true
    }
}


来源:https://stackoverflow.com/questions/25738677/androidmanifest-xml-and-tests-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!