android test fixtures
android, testing
Solution
It depends if you really mean unit test or instrumented tests (like using espresso and stuff)...
Unit tests:
- Put your fixtures in `src/test/resources` (so e.g. `src/test/resources/fixture.json`)
- Access them from your test classes e.g. using:
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("fixture.json")
Instrumented tests:
- Put your fixtures in `src/androidTest/assets/` (so e.g. `src/androidTest/assets/fixture.json`)
- Access them from your test classes e.g. using:
InputStream is = InstrumentationRegistry.getContext().getResources().getAssets().open("fixture.json")
Here are some examples of how you can convert `InputStream` to `String`.
Here's a pretty good post describing different cases.
P.S. I know this question is 6+ years old... answering for any future searches.
Problem
I am working on an android app and I have created a new test project for unit tests. Where's recommended to store the test fixtures (like xml files and the like) and what's the proper way to access it ?