繁体   English   中英

AndroidManifest.xml和Android Studio中的测试

[英]AndroidManifest.xml and tests in Android Studio

我有一个带有应用程序源目录的基本Android项目,并通过Android Project模板设置了测试源目录。

我了解到,Android测试使用特定于正在运行的测试的Androidmanifest.xml,在该测试中,我们必须指定检测类型和目标包:

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

在Android Studio中,我可以使用android测试配置运行测试, 而无需指定特定于我的测试的AndroidManifest.xml文件(我的测试源中没有AndroidManifest.xml文件)。

当我在Android Studio中运行测试时,可以看到在运行测试之前已经部署了我的应用程序, 然后启动了测试。 因此,我猜想Android Studio自己管理测试过程以及特定于测试的AndroidManifest.xml的生成。

我对么 ?

根据Android Gradle插件的文档( http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing ),当描述如何为Android测试设置源集时:

sourceSet不应包含AndroidManifest.xml,因为它是自动生成的。

您可以直接在构建文件中为测试配置参数,例如InstrumentationTestRunner,如下所示:

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

由于Android Gradle插件是根据Scott Barta的答案进行更新的,因此您现在可以这样编写:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM