Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the gradlew task assembleAndroidTest and what are the Test applications in Android?

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.

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.

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

What are the Test applications?

Also, what is -DtestBuildType=debug?

like image 641
evianpring Avatar asked May 19 '19 23:05

evianpring


People also ask

What is gradlew Android Studio?

You can execute all the build tasks available to your Android project using the Gradle wrapper command line tool. It's available as a batch file for Windows ( gradlew. bat ) and a shell script for Linux and Mac ( gradlew.sh ), and it's accessible from the root of each project you create with Android Studio.

What does gradlew assembleDebug do?

For instance, to build a debug version of your Android application, you can run ./gradlew assembleDebug from the root of your repository. In a default project setup, the resulting apk can then be found in app/build/outputs/apk/app-debug.

What is called Gradle in Android?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


Video Answer


1 Answers

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"
  ..

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')

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 .."
like image 165
odiggity Avatar answered Oct 19 '22 20:10

odiggity