2019/06/18 potatotips #62
©2019 Wantedly, Inc.QPUBUPUJQT!XBLXBL 3ZP4BLBHVDIJ2019.6.18 -5FTUNVMUJQMF"1,T XJUI3PCPMFDUSJD
View Slide
©2019 Wantedly, Inc.Ryo Sakaguchi• Wantedly, Inc - Wantedly People• Android/CI/CD/UI• Kotlin/Sake/Beer/MtG/Guitar…• Twitter/GitHub: @wakwak3125
©2019 Wantedly, Inc.1. Robolectric• What’s this?• Why use this?• Binary Resources2. Testing the Multiple APKs w/Robolectric• Problem• Why?• Way to resolve3. WrapUpToday’s topics What I talk today
©2019 Wantedly, Inc.Robolectric
©2019 Wantedly, Inc.is a framework that brings fast and reliable unit tests to Android. Tests run inside the JVM on your workstation in seconds.Robolectricrobolectric.org
©2019 Wantedly, Inc.API is common to androidx.test
©2019 Wantedly, Inc.Binary Resources
©2019 Wantedly, Inc.Use resources processed using the Android build toolchain. Loads and handles resources using the same logic as on an actual Android device.Binary Resourcesrobolectric.org
©2019 Wantedly, Inc.Testing the Multiple APKs w/Robolectric
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricRobolectric + Multiple APKsI got this error…> expected one element but was:
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricWhy this cause?Let's take a look source code a bithttps://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/PackageForUnitTest.java
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricArtifactTypeTarget artifact type to get. In this case, PROCESSED_RES(APK includes only resources)https://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/PackageForUnitTest.java
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricBuildableArtifactOutput Fileshttps://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/PackageForUnitTest.java
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricWhen you split APK…This should become multiplehttps://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/PackageForUnitTest.java
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricBuildElementsIt returns BuildElements that match artifact type.https://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/PackageForUnitTest.java
©2019 Wantedly, Inc.Problem Testing the Multiple APKs w/RobolectricIterables.getOnlyElementReturns the single element contained in iterable. IllegalArgumentException - if the iterable contains multiple elementshttps://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/tasks/PackageForUnitTest.java
©2019 Wantedly, Inc.
©2019 Wantedly, Inc.Way to resolve Testing the Multiple APKs w/RobolectricI found some ways to resolve this• Use Android App Bundle(Recommended)• Android App Bundle allows you to separate the publish settings andbuild settings.(On publish, bundleXXX. On develop, assembleXXX)• And also reduce your APK size!• Introduce custom Gradle properties and switch it by commandline arguments.• It’a not bad idea, but when you run tests on Android Studio, youhave to set the arguments every time you want.• Until yesterday, I have been used this.Please choice by yourself
©2019 Wantedly, Inc.Test multiple APKs with RobolectricWrapUp• Test w/Robolectric + Binary Resources + Multiple APK does notwork correctly.• I recommend to use Android App Bundle• You can fine issue here https://github.com/robolectric/robolectric/issues/4942
Thanks!©2019 Wantedly, Inc.