Mirouf
Mirouf

Reputation: 87

AndroidManifest.xml and tests in Android Studio

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 ?

Upvotes: 1

Views: 3703

Answers (2)

laomo
laomo

Reputation: 436

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
    }
}

Upvotes: 3

Scott Barta
Scott Barta

Reputation: 80010

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
    }
}

Upvotes: 3

Related Questions