您好,当我在 androidTest list 文件中重写应用程序时,它不起作用。这是我在 androidTest
文件夹中的 AndroidManifest.xml
文件:
<?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>
这是 main
文件夹中原始 AndroidManifest.xml
的一部分:
<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>
事实上我调试了它,并从被测 Activity 的断点调用 getApplication(),它返回 .app.Application
而不是 ApplicationAndroidTest
实例。
您知道为什么忽略来自 androidTest 的 android list 文件吗?
最佳答案
作为解决方法,我使用了自定义测试运行器类:
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);
}
}
它对我来说很好。希望对某人有所帮助。
关于AndroidTest 不使用测试应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36935756/