views:

477

answers:

1

I want to test parsing of data returned from server.

I thought I might create several test XML files and then feed them to the sax parser which uses my custom data handler (as in the application that I test).

But where should I put those test XMLs?

I tried with [project_root]/res/xml, but then I get the error:

android.content.res.Resources$NotFoundException: Resource ID #0x7f040000 type #0x1c is not valid at android.content.res.Resources.loadXmlResourceParser(Resources.java:1870) at android.content.res.Resources.getXml(Resources.java:779)

Does that mean that the xml is invalid, or that android couldn't find the XML file? (I use the same XML that comes from the server - copied it from the firebug's net panel and pasted into the file).

Can I somehow read that XML as a text file, since getContext().getResources().getXml(R.xml.test_response1) returns XmlResourceParser instead of String (which I'd prefer)?

+1  A: 

Put you xmls in MyAppTest/assets, for example MyAppTest/assets/my.xml, and then read it using

InputStream myxml = getInstrumentation().getContext().getAssets().open("my.xml");

then you can invoke the parser with this stream.

dtmilano
java.io.FileNotFoundException: test_response1.xml at android.content.res.AssetManager.openAsset(Native Method)
zorglub76
I don't know what's going on.. When I call getContext().getAssets().list("/"), I get a list of several files and folders among which is "assets" folder. When I then list files in "/assets" folder, I get nothing - as if the folder is empty...
zorglub76
Depending on where is the xml file (in your app's assets or your test's assers) you need the right context to find it through getAssets().
dtmilano