I\'m trying to create a test fixture using Fitnesse
framework, and I want to test a function which retrieves data from a server (RESTFUL service). My test case
You can fix this problem and test within your IDE really easily by using Roboelectric.
As dtmilano said, you can't run Android code on your laptop as is, but Roboelectric basically substitutes the actual method implementations for the stubs in Android.jar.
Two things to watch out for if you go with this solution:
Make sure that your JAR import is above the Android JAR in your dependencies list if using IntelliJ
It defaults to blocking HTTP requests under the assumption that you don't actually want to change the state of a server somewhere. You can, however, disable this quite easily: Roboelectric.getFakeHttpLayer().interceptHttpRequests(false);
I had this same issue because of the "static" declaration. In my case, .build() caused the issue in a static variable. The simple solution was to not declare the variable static. It can be final. Try removing "static" from the getJsonArrayFromUrl method and see if it works.
android.jar
contains only stub implementation of the classes. It provides the means for you app to build, once you have your APK you must run it on an android device or emulator.
If I'm not wrong you are trying to run on host's JVM.
As mentioned previously, Android jar
s are not good for anything beyond compiling. Even most innocent things are stubbed out completely. But you can still use them in host VM unit tests with good mocking frameworks. My choice is jmockit:
Not sure whether it will work with Fitnesse though