Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test android audio recording app using robolectric

I just want to know whether it is possible to unit test android audio recorder app using the Robolectric framework.

As far as I know, Robolectric does not use the emulator or real device for testing. But in audio recording app, I need to test whether audio is getting recorded? Does it get stored at the specified location on SD card? Does it get played using the media player? and many other scenarios.

I have looked into many Robolectric tutorials but they do not answer my question. I had also asked this question( https://groups.google.com/forum/#!topic/robolectric/JLKrRGsvIkU ) in Robolectric google group which went unanswered. Is the concept of shadows helpful here?

like image 349
Sharath Kumar Avatar asked Aug 19 '16 10:08

Sharath Kumar


1 Answers

I guess you use the MediaRecorder for recording audio.

Robolectric has already a Shadow for the MediaRecorder. This shadow only stores properties and the current stopped/started state. There is no audio recording implemented. For details, see https://github.com/robolectric/robolectric/blob/master/shadows/framework/src/main/java/org/robolectric/shadows/ShadowMediaRecorder.java

Yes, you can unit test your app with Robolectric but real audio recording will not work. One thing you can do is to put a dummy record file to the target path when other code parts work with this file.

Also, with other tools like Espresso it could be hard to test.

like image 73
nenick Avatar answered Sep 27 '22 23:09

nenick