Android的单元测试轻慢不得 [英] Android unit test not mocked
问题描述
我跟着这个指南
https://sites.google.com/a /android.com/tools/tech-docs/unit-testing-support
但我还是坚持了这个错误是:
junit.framework.AssertionFailedError:异常的构造函数:testSaveJson(了java.lang.RuntimeException:方法放在org.json.JSONObject轻慢不得见https://sites.google。 COM / A / android.com /工具/技术含量文档/详情单元测试支持。
我通过修改摇篮打造像导游说,但它不会有所作为
testOptions {
unitTests.returnDefaultValues =真
}
JSON是捆绑了Android SDK,所以你只被击中的存根。您可以在JSON罐子,这将提供实物使用拉。
要做到这一点,你需要添加到您的build.gradle:
testCompile文件(库/ json.jar')
请注意,你不能把它直接从Maven的中央,所以 testCompile'org.json:JSON:20140107
将无法正常工作,你必须抓住瓶子里。
请注意,JSON的最新版本是专为Java内置8个,所以你需要抓住 20140107 一>
I followed this guide https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support but i am stuck with this error:
junit.framework.AssertionFailedError: Exception in constructor: testSaveJson (java.lang.RuntimeException: Method put in org.json.JSONObject not mocked. See https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support for details.
I modified by Gradle build like the guide says but it doesn't make a difference
testOptions {
unitTests.returnDefaultValues = true
}
JSON is bundled up with the Android SDK, so you'll just be hitting a stub. You can pull in a JSON jar, which will provide real objects to use.
To do this, you'll need to add this to your build.gradle:
testCompile files('libs/json.jar')
Note that you can't pull it directly in from maven central, so testCompile 'org.json:json:20140107'
won't work, you have to grab the jar.
Note that the latest version of JSON is built for Java 8, so you'll need to grab 20140107
这篇关于Android的单元测试轻慢不得的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!