我跟着本指南 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/tools/tech-docs/unit-testing-support https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support了解详情。
我按照指南所述通过 Gradle build 进行了修改,但这没有什么区别
testOptions {
unitTests.returnDefaultValues = true
}
JSON 与 Android SDK 捆绑在一起,因此您只需使用存根即可。您可以拉入一个 JSON jar,它将提供可供使用的真实对象。
为此,您需要将其添加到您的 build.gradle 中:
testImplementation 'org.json:json:20140107'
或者,您可以下载并包含该 jar。
testCompile files('libs/json.jar')
请注意,最新版本的 JSON 是为 Java 8 构建的,因此您需要获取20140107 http://mvnrepository.com/artifact/org.json/json/20140107您可能还需要清理并重建项目。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)