I am trying to unit test a class that does SAX parsing and creates an object. This class takes a string as a parameter representing the URL of a document on the internet, parses it and then creates an object based on the contents.
I don't want to have the unit tests actually access the network, so I'd like to have a few test xml files to parse. However I can't figure out how to access them from my AndroidTestCases. I don't want to include the test files with the actual application, I want them in the test project (it's a separate project, as is the norm for Android tests from what I could gather - due to the need to have a custom AndroidManifest.xml, for one).
One way would be to put the XML files in the test project's assets directory, I can read them using getContext().getAssets().open(filename
) into an InputStream
in the test case, but my class expects a URL string. I'd rather not have to provide an InputStream to this class instead of the current URL string. I can test just the parsing by making two methods, one that takes a string and one an Inputstream, and test the second, but how can I then test the one that just takes a string?
How should I design my class and or tests to circumvent this problem?