For example, testing input/output to an image file. To create the file, the following code is used (summary):
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile("tempImage",".jpg",storageDir);
mCurrentPhotoPath = image.getAbsolutePath();
mCurrentPhotoURI = FileProvider.getUriForFile(this,"com.example.android.fileprovider",image);
File photoFile = image;
When I try to write an integration test using this code to create a file, I have issues with the getExternalFilesDir
and this
(which is a context). How can I effectively test without having an activity or context to pass? Can I generate one?