2 years ago
#60652

Damn Vegetables
Local test, open a file in the "assets" directory
First, I am talking about "test", not "androidTest". I created a test data file and put it in "test"'s asset directory. Android Studio shows that it belongs to the test, not AndroidTest, as below:
Now, how can I open that file in a local test? I guess I could specify the full path or a relative path, but I think that there probably is a way to specify file name only, like the androidTest example:
getInstrumentation()
.getContext()
.getResources()
.getAssets()
.open("test.txt");
PS: In case there is no such convenient way, I have tested things a little bit and the test's working directory is the "app" directory, so the following code worked.
val f = File(".\\src\\test\\assets\\test.txt");
val text = f.readText();
android
junit
android-testing
0 Answers
Your Answer