Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing with Android XmlPullParser on the JVM

I'm trying to set-up unit test cases for my application.

A critical part of the app parses XML files with org.xmlpull.v1.XmlPullParser. As this part is low-level, isolated and independant from activities, context, views, etc., I really wanted to make it run locally on the JVM, to avoid having to plug or emulate a device all the time.

However when running something like this on the JVM:

XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
...

I get the famous:

Exception in thread "main" java.lang.RuntimeException: Stub!
    at android.util.Xml.newPullParser(Xml.java:15)
    ...

Is there a way around this?

like image 916
Eric Leibenguth Avatar asked Jul 07 '15 15:07

Eric Leibenguth


1 Answers

I managed to go around this problem by using Robolectric in Android-Studio. I followed this tutorial, and stumbled upon this other problem.

Now it works fine except I can't see the standard output when running tests.

like image 65
Eric Leibenguth Avatar answered Oct 17 '22 14:10

Eric Leibenguth