How to unit test Android sound recording application using robolectric

I just want to find out if the w ^> w audio audio recorder application can be used using the Robolectric platform.

As far as I know, Robolectric does not use an emulator or a real device for testing. But in a sound recording application I need to check if sound is being recorded? Is it stored in the specified location on the SD card? Is it played using a media player? and many other scenarios.

I learned a lot of Robolectric lessons, but they do not answer my question. I also asked this question ( https://groups.google.com/forum/#!topic/robolectric/JLKrRGsvIkU ) in the Robolectric google group, which went unanswered. Is the concept of shadows useful here?

+4
source share
1 answer

I use MediaRecorder to record sound.

Robolectric already has a shadow for MediaRecorder. This shadow only stores properties and the current state of stop / start. Audio recording not implemented. See https://github.com/robolectric/robolectric/blob/master/robolectric-shadows/shadows-core/src/main/java/org/robolectric/shadows/ShadowMediaRecorder.java for details

Yes, you can unit test your application with robolectric, but real sound recording will not work. One thing you can do is put the dummy record file in the target path when other parts of the code work with this file.

, , .

+4

Source: https://habr.com/ru/post/1651771/


All Articles