问题描述
我是测试领域的新手,对 Android 测试领域更甚.在对有助于在 android 上进行测试的 Robolectric 进行研究时,最让我感到困惑的是一件事.有时在网络上,我看到人们在引用 Robolectric 时在 gradle 构建脚本的依赖项中使用 testCompile
关键字,而其他人使用 androidTestCompile
.肯定不能两者都有效吗?
I'm new to testing world and even more to Android testing world. While doing research on Robolectric that aids with tests on android one thing confuses me the most. Sometimes on the web I see people using testCompile
keyword in dependencies of the gradle build script when referencing Robolectric while others use androidTestCompile
. Certainly both can't be valid?
有人能解释一下两者之间的区别吗?在使用 Robolectric 时应该使用哪一个?
Can somebody explain the difference between the both and which of these should be the one used when using Robolectric?
推荐答案
Simply testCompile
是单元测试(位于 src/test 中的那些)和 androidTestCompile
用于测试 api(位于 src/androidTest 中).由于您打算编写单元测试,您应该使用 testCompile
.
Simply testCompile
is the configuration for unit tests (those located in src/test) and androidTestCompile
is used for the test api (that located in src/androidTest). Since you are intending to write unit tests, you should use testCompile
.
更新: 两者的主要区别在于 test
源集在常规 Java JVM 中运行,而 androidTest
源集测试在Android 设备(或模拟器).
Update: The main distinction between the two is the test
sourceset runs in a regular Java JVM, whereas the androidTest
sourceset tests run on an Android device (or an emulator).
这篇关于对 Android Gradle 中的 testCompile 和 androidTestCompile 感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!