问题描述
我有一个基本的Android项目,其中包含应用程序源目录,并测试了由Android Project模板设置的源目录.
I have a basic Android project with an application sources directory and tests sources directory set up by the Android Project template.
我已阅读到Android测试使用特定于正在运行的测试的Androidmanifest.xml,在该测试中,我们必须指定检测类型和目标程序包:
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" />
在Android Studio中,我可以使用android测试配置来运行测试,而无需指定我的测试专用的AndroidManifest.xml文件(我的测试源中没有AndroidManifest.xml文件).
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).
当我在Android Studio中运行测试时,可以看到我的应用程序在测试运行之前已经部署完毕,然后然后启动了我的测试.因此,我猜想Android Studio自己管理测试过程以及特定于测试的AndroidManifest.xml的生成.
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.
我正确吗?
推荐答案
根据Android Gradle插件的文档( http://tools.android.com/tech-docs/new-build-system/用户指南#TOC测试),描述如何为Android测试设置源集:
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:
您可以直接在构建文件中为测试配置参数,例如InstrumentationTestRunner,如下所示:
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
}
}
这篇关于AndroidManifest.xml和Android Studio中的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!