Reputation: 2560
Hi I faced that when I rewrite application in androidTest manifest file, it does not work. This is my AndroidManifest.xml
file in androidTest
folder:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.app"
android:installLocation="auto">
<application
tools:replace="android:name"
android:name=".app.ApplicationAndroidTest" />
</manifest>
This is part of original AndroidManifest.xml
from main
folder:
<application
android:name=".app.Application"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/Theme">
...
</application>
In fact I debugged it, and called getApplication() from breakpoint in activity under test, it returns .app.Application
instead of ApplicationAndroidTest
instance.
Do you have any ideas why android manifest file from androidTest is ignored?
Upvotes: 5
Views: 2040
Reputation: 10267
Changing application class at androidTest xml doesn't affect the app itself (tested app) but the additional android test apk that ships to the device for enabling tests. I'm not sure what is the exact meaning of application if any to android test apk.
anyhow busylee workaround is the available solution.
Important note: when defining custom instrumentation runner, it is required to run the tests with the custom runner, that can be done at Android Studio by editing run configuration of test run, under AndroidTests section with a test selected, there is 'Specific instrumentation runner (optional)' option.
Upvotes: 0
Reputation: 2560
As A workaround I used custom test runner class:
public class UiTestsRunner extends AndroidJUnitRunner {
@Override
@NonNull
public Application newApplication(@NonNull ClassLoader cl, @NonNull String className, @NonNull Context context)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return Instrumentation.newApplication(ApplicationAndroidTest.class, context);
}
}
It seams ok for me. Hope it helps someone.
Upvotes: 6