android.unitTests.returnDefaultValues如何工作? [英] How does android.unitTests.returnDefaultValues work?

查看:76
本文介绍了android.unitTests.returnDefaultValues如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Android项目的build.gradle中具有以下内容应该做什么.但是它是如何工作的呢?到底返回什么默认值?它们如何与真实"值进行比较?

I know what having the following in an Android project's build.gradle is supposed to do. But how does it work? And what exactly are the default values returned? How do they compare with "real" values?

android {
    // ...
    testOptions { 
        unitTests.returnDefaultValues = true
    }
}

推荐答案

每个文档(添加了重点):

如果android.jar中的Android API引发的异常对于您的测试而言是有问题的,则可以更改行为,以便通过在项目的项目中添加以下配置,使方法改为返回null或零.顶层build.gradle文件:

If the exceptions thrown by Android APIs in the android.jar are problematic for your tests, you can change the behavior so that methods instead return either null or zero by adding the following configuration in your project's top-level build.gradle file:

android {
  ...
  testOptions {
    unitTests.returnDefaultValues = true
  }
}

警告:应谨慎设置returnDefaultValues属性为true.空/零返回值会在您的测试中引入回归,这很难调试,并且可能允许失败的测试通过.只能将其用作最后的手段.

Caution: Setting the returnDefaultValues property to true should be done with care. The null/zero return values can introduce regressions in your tests, which are hard to debug and might allow failing tests to pass. Only use it as a last resort.

这篇关于android.unitTests.returnDefaultValues如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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