jeudi 28 juillet 2016

How to test Bitmap related code?

I am working on an Imaging application. I want to implement unit testing for Bitmap related functions. I also need to see the output Bitmap.

I tried two options :

  1. run the test in test/java so I can dump the output image to a file on my Mac and open it manually. But I got an android.graphics.BitmapFactory not mocked.

  2. run the test in androidTest/java so BitmapFactory is fully implemented but:

    • I got access denied when trying to pull the file using adb pull using mockContext.openFileOutput(fileName, Context.MODE_PRIVATE)
    • I cannot write to an external directory because I cannot grant write access without and Activity using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
    • If I make it work, I don't know how to hook to the gradle task to automate the pull command / or to grand write access at runtime.

So how to test Bitmap related code ? I am out of options !

Aucun commentaire:

Enregistrer un commentaire