Reputation: 83517
I have a CSV file that I want to make available for my Android testing suite. I don't want it to be available for the main app, though. I saved it in the assets
folder of my test project. Then I try to access it from a test using
context.getAssets().open(DATA_ASSET);
where DATA_ASSET
is declared as
DATA_ASSET = "cards.csv"
I set the context
to refer to the Activity which I am testing. However, this obviously won't work as I have it since it will look in the assets of the main app. I see two possibilities to fix this:
Context
which refers to the test project's resources and assetsI haven't found any way to do either of these yet. Perhaps there is a third solution that I haven't thought of. How can I access the assets that are installed with the test project?
Upvotes: 0
Views: 380
Reputation: 4821
If you're subclassing InstrumentationTestCase
or a similar class, you can obtain a Context
for the test project by doing the following:
Context ctx = getInstrumentation().getContext();
Upvotes: 1