March 2015
Beginner to intermediate
274 pages
6h 1m
English
This test implements an AndroidTestCase as all we need is a Context to be able to reference our assets folder. Also, we have written the parsing inside of the test, as the point of this test is not how to parse xml but how to reference mock assets from your tests:
public class ParserExampleActivityTest extends AndroidTestCase {
public void testParseXml() throws IOException {
InputStream assetsXml = getContext().getAssets()
.open("my_document.xml");
String result = parseXml(assetsXml);
assertNotNull(result);
}
}
}The InputStream class is obtained by opening the my_document.xml file from the assets by getContext().getAssets(). Note that the Context and thus the assets obtained here are from the tests package and not from the Activity ...
Read now
Unlock full access