How to unit test JSON parsing

后端 未结 5 1362
北恋
北恋 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:32

    I had the same problem but I found a better way. The framework Roboelectric does the job. At first I just added the roboelectric.jar as external library (because I don't use Maven) to the build path of my Java JUnit test project and as "class annotation" I added @RunWith(RobolectricTestRunner.class). But then I got a NoClassDefFoundError: android/net/Uri. After I still added the android.jar itself used by the corresponding Android project (although the Android library with its android.jar was already a part of my build path), it works.

提交回复
热议问题