Issue
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
}
Solution
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:
testImplementation 'org.json:json:20140107'
Alternatively, you can download and include the jar.
testCompile files('libs/json.jar')
Note that the latest version of JSON is built for Java 8, so you'll need to grab 20140107 You may also need to clean and rebuild the project.
Answered By - Ben Pearson
Answer Checked By - Clifford M. (JavaFixing Volunteer)