I have a MainMenu activity that gets data from file and displays it. I want the data to be deleted at the start of each espresso test and to not persist between tests.
I have tried the following:
Context mContext;
@Before
public void setUp() {
mContext = InstrumentationRegistry.getInstrumentation().getContext();
File[] files = mContext.getFilesDir().listFiles();
if(files != null){
for(File file : files) {
file.delete();
}
}
}
However, it is not deleting the files. I believe the context might not be correct. Is there a way to clear internal storage at the start of an espresso test?
The files are '.ser' files.
Have you tried using adb shell commands?
One thing I tried that was helpful in deleting files in an Espresso test was executing ADB shell commands programmatically. Something like this:
(Kotlin sample)
Java would look something like this:
As for seeking out files of a specific type you can use the FilenameFilter or FileFilter interfaces for that. See this answer and this page for examples of how you can do this.
An example might look like this:
Hope that helped.