问题
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?
回答1:
I guss you use the MediaRecorder for recording audio.
Robolectric has already a Shadow for the MediaRecorder. This shadow only stores properties and the current stoped/started state. There is no audio recording implemented. For details see https://github.com/robolectric/robolectric/blob/master/robolectric-shadows/shadows-core/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.
来源:https://stackoverflow.com/questions/39036344/how-to-unit-test-android-audio-recording-app-using-robolectric