简体   繁体   English

测试Android应用发布版本变体

[英]Testing Android app release build variant

I have written many unit and instrumented tests for my Android app. 我为Android应用程序编写了许多单元测试和仪器测试。 So far, I only run these against the debug build variant. 到目前为止,我仅针对调试构建变体运行它们。 Is it necessary to run tests against the release build variant? 是否有必要针对发布版本进行测试? What difference can there be that might give different results from testing? 从测试中得出不同的结果会有什么区别? The main one that I can think of is when ProGuard is enabled, which I haven't done. 我能想到的主要内容是启用ProGuard的时间,但尚未完成。 What will ProGuard do that makes it necessary to run my test suite? ProGuard将做什么,这使得必须运行我的测试套件? What other issues should I be aware of that require testing the release build variant? 我还应该知道还有哪些其他问题需要测试发行版本?

Is it necessary to run tests against the release build variant? 是否有必要针对发布版本进行测试?

I think you should. 我想你应该。

What difference can there be that might give different results from testing? 从测试中得出不同的结果会有什么区别?

A couple of examples: 几个例子:

  • You might have code that uses fields of the BuildConfig class to enable/disable certain workflows. 您可能具有使用BuildConfig类的字段来启用/禁用某些工作流的代码。 Some libraries might also use that, especially BuildConfig.BUILD_TYPE . 一些库也可能会使用它,尤其是BuildConfig.BUILD_TYPE It's common to do things like: 通常会执行以下操作:

     if (BuildConfig.BUILD_TYPE.equals("debug") { ACRA.init(...); Stetho.init(...); ... } 

    but have code fail in release builds due to trying to use components/libraries that were not initialized correctly. 但是由于尝试使用未正确初始化的组件/库,导致代码在发行版本中失败。

  • As you mentioned, ProGuard might throw away some of your classes unless it's properly configured (eg imagine you forgot to add rules for some 3rd party library). 如您所述,ProGuard可能会丢弃某些类,除非对其进行了正确配置(例如,假设您忘记为某些第三方库添加规则)。 Running your tests against the release variant ensures that the ProGuard configuration is correct. 针对发行版本运行测试可确保ProGuard配置正确。

What will ProGuard do that makes it necessary to run my test suite? ProGuard将做什么,这使得必须运行我的测试套件?

ProGuard might remove classes/methods/fields that are, for example, loaded via reflection unless you add the @Keep annotation to them. ProGuard可能会删除通过反射加载的类/方法/字段,例如,除非您向它们添加@Keep批注。 It might also rename classes used by libraries like Realm, Retrofit, Gson or Volley resulting in all unit and integration tests passing on debug builds (where ProGuard isn't enabled) but failing on release builds. 它还可能重命名Realm,Retrofit,Gson或Volley等库使用的类,从而导致所有单元测试和集成测试都通过调试版本(未启用ProGuard),但在发布版本中失败。 You definitely want to test these before shipping our a new APK. 您肯定要在发货我们的新APK前对其进行测试。

What other issues should I be aware of that require testing the release build variant? 我还应该知道还有哪些其他问题需要测试发行版本?

The release build might also apply PNG crunching, specify different parameters via the buildConfigField method in Gradle, apply splits by ABI or density or enable/disable multidex and others. 发布版本可能还会应用PNG buildConfigField ,通过Gradle中的buildConfigField方法指定不同的参数,应用按ABI或密度拆分或启用/禁用multidex等。 All of these can have implications in the way that your app works, so why not be on the safe side and test them too. 所有这些都会对您的应用程序的运行方式产生影响,因此,为什么不安全地进行测试。

Another frequent problem that you can catch using these is ensure that you've not accidentally put code in the wrong location (eg /src/debug/java/ ) that happens to be loaded in debug builds but not in other variants. 使用它们可以发现的另一个常见问题是,确保您没有将代码错误地放在错误的位置(例如/src/debug/java/ ),而该错误恰巧是在调试版本中加载的,而不是在其他变体中加载的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android测试版本构建 - Android testing release build 构建 android 应用程序时出现错误,其中发布版本变体未出现在调试或测试版中 - Getting error when building android app with release build variant that does not appear in debug or beta Android - 仅在发布版本变体上执行Gradle任务 - Android - Only execute Gradle task on release build variant 在Android应用程序中获取产品风味或构建变体 - Get product flavor or build variant in an android app 测试应用程序更新时,为 Android 版本构建签名的 APK 静默阻止安装 - Installation silently blocked for Android release build signed APK when testing App update 发布构建变体因“androidx.fragment:fragment-testing”库的 debugImplementation 而失败 - Release build variant failed with debugImplementation for "androidx.fragment:fragment-testing" library 测试Android应用的发布和受保护版本-NoSuchMethodError - Testing release and proguarded version of Android app - NoSuchMethodError Android版平台上的多版应用程序? [Android Build Variant] - Multi Edition of an app on Android-platform? [Android Build Variant] 在Android中发布使用Proguard和build-variant构建APK时出现错误 - Getting error when build apk using proguard and build-variant is release in android 在 Android Studio 3.5 中使用 Build Variant 重命名应用程序的存档名称 - Rename archive Name for app with Build Variant in Android Studio 3.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM