XML : Android Unit test for XML parsing

I am attempting to write a unit test for parsing an XML document in my Android app in Android Studio. I using the same approach I used 2 years ago and I'm wondering if things have changed with the ties. In my approach, I create a Java library where the parser class and test will live. I have to convince Android Studio to copy the test input XML document to a place where the test class can find it at runtime using some Gradle logic:

  testClasses.doFirst {      ant.copy(todir: sourceSets['test'].output.classesDir) {          fileset(dir:sourceSets['test'].output.resourcesDir)      }  }    

I load the XML at runtime using a Java 1.2 technique

  this.problems = getClass().getClassLoader().getResourceAsStream("input.xml");    

The xml is then found and fed into my parser which needs the XML pull API. I set a dependency on the KXML pull API in the Java library Gradle build but then I need to do a work around to avoid the API being redundantly compiled in since Gradle doesn't yet support a "provided" scope. The whole process is a mess that I'd rather avoid.

Now I know A/S now supports POJO unit tests within the main Android module but even that feels awkward and I don't know if it scratches my itch. What I want to know is wether there is a better way to go about this? How does one test a basic XML parse in the most simplest way?

No comments:

Post a Comment