gradlew任务assembleAndroidTest是什么,Android中的Test应用程序是什么? [英] What is the gradlew task assembleAndroidTest and what are the Test applications in Android?

查看:174
本文介绍了gradlew任务assembleAndroidTest是什么,Android中的Test应用程序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用React-Native编码了一段时间了,当我需要编写一些本机Android代码时也是如此.但是,直到开始使用使用该特定gradle任务的库之前,我才看到此gradle任务.

I've been coding in React-Native for a while and when I need to I write some native Android code as well. However, I had not seen this gradle task until I started using a library which used this particular gradle task.

该库是一个端到端测试库(detox),它使用此命令"cd android&& ./gradlew assembleDebug assembleAndroidTest -DtestBuildType = debug&& cd .."来构建将在自动e2e测试中使用的android .apk .实际上,它构建了两个apk,一个是调试版本,另一个是AndroidTest版本,但我不知道后者来自哪里,它的配置位置或文档的相关位置.

That library is an end-to-end testing library (detox), and it uses this command "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd .." to build the android .apk that will be used in the automated e2e test. Actually it builds two apks, the debug one and the AndroidTest one, but I don't know where the latter comes from or where it's configured or where the docs are about this.

我搜索了一个小时,除了这个简短的描述外,没有找到任何其他内容: assembleAndroidTest-组装所有的Test应用程序.

I searched for an hour and did not find anything other than this very short description: assembleAndroidTest - Assembles all the Test applications.

什么是测试应用程序?

还有,什么是 -DtestBuildType = debug ?

推荐答案

当您运行UI测试(也称为有工具的测试)时,会生成两个apk.一个是您的应用程序的apk,您可能熟悉的apk,另一个是其中包含所有UI测试的apk.运行测试时,两个APK均上传到设备. assembleAndroidTest 是gradle命令,用于构建第二个测试apk.默认情况下, assembleAndroidTest 将使用调试构建类型构建测试apk.您可以通过将其添加到build.gradle文件中来更改构建类型:

When you run UI tests (also called instrumented tests) there are two apks that are built. One is your application's apk, the apk that you're probably familiar with, and a second apk that has all of the UI tests in it. When you run the test, both apks are uploaded to the device. assembleAndroidTest is the gradle command to build the second test apk. By default assembleAndroidTest will build the test apk with the debug build type. You can change the build type by adding this to your build.gradle file:

android {
  testBuildType "release"
  ..

Detox使用参数 -DtestBuildType = debug 进行的操作使这一步骤更进一步,并允许您通过gradle任务动态指定测试apk构建类型.他们通过将其添加到他们的build.gradle文件中来做到这一点:

What Detox is doing with the parameter -DtestBuildType=debug is taking this one step further and allowing you to dynamically specify the test apk build type through the gradle task. They do this by adding this to their build.gradle file:

testBuildType System.getProperty('testBuildType', 'debug')

您可能想要执行此操作的一个潜在原因是,如果要在发行版本类型上运行测试,以确保测试仍通过proguard进行.因此,它看起来像:

One potential reason you might want to do this, is if you want to run your tests on a release build type in order to make sure that the tests still pass with proguard. So it would look like:

./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release && cd .."

这篇关于gradlew任务assembleAndroidTest是什么,Android中的Test应用程序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆