11

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?

Giulio Caccin
  • 2,962
  • 6
  • 36
  • 57
evianpring
  • 3,316
  • 1
  • 25
  • 54

1 Answers1

19

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 .."
odiggity
  • 1,496
  • 16
  • 29