How to unit test JSON parsing

后端 未结 5 1361
北恋
北恋 2020-12-08 00:57

I\'m working on an Android app in which I download JSON data from a web service. The class parsing the data looks something like this:

public class JsonCours         


        
5条回答
  •  误落风尘
    2020-12-08 01:54

    All you need to do is add the following line to the dependency section in your build.gradle:

    testImplementation 'org.json:json:20140107'
    

    Note that you also need to use Android Studio 1.1 or higher and at least build tools version 22.0.0 or above for this to work!

    testImplementation means that the dependency is included as a test dependency will only be used when your project is being compiled for executing unit tests. The supplied jar will not be included in your APK and will only be used to replace the missing classes in the org.json package.

提交回复
热议问题