Search code examples
javaandroidunit-testingjvmxmlpullparser

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?


Solution

  • 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.