java - File location for unit testing -
This is a very simple question, for which I can not find a solution. I have a very complicated Android app that uses the camera and takes some breaks for the pictures. Now I want to write unit tests for some tasks, but I have not been able to load any files.
In an Android test project where I should paste the image to test and how can I load that image? This can not be the best solution because it can drain your project considerably though, your test In the case of lack of writing codes to download an image, I'm not sure what another approach might be. Just, I have 'test' drawables in my resources and I load them bitmap, then refer them to their tests somewhere on the disk. This is the code I use: You probably want to make this method a bit stronger. Finally, you can simply hide your screen pictures in your property folder for your project. You can then retrieve them in your activity folder using the Edit I think after some research, a better solution, your file of your test project Adding to the property and using the file object? I have a generic
junit.framework.TestCase class on which to send a class to
file , the exam is required. thank you in advanced!
Secure the public fileEserSizeGateOnstastAstorage (Activity Activity, StringPixelName, IIDID) {bitmap bitmap = bitmapfactoryDicDRSOSR (activity.GetterSources (), ImageID) ; File picFile = null; OutputStream OS = Faucet; Try {PicFile = new file (Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES), picFileName); PicFile.createNewFile (); OS = new file optupstream (pixfile); Bitmap.compress (bitmap.compress format.jpeg, 100, os); } Hold (IOException e) {e.printStackTrace (); } Return file; }
getAssets () or use the path that should be like the
file: /// android_asset / Your_file_name.jpg
InputStream input = this.getContext (). GetAssets () Open ("file.jpg"); . You will need to call it from the class that comes from
InstrumentationTestCase or, I think,
ActivityInstrumentationTestCase2 . Then you can manipulate the input stream that you need
Comments
Post a Comment