简体   繁体   English

如何使用 robolectric 对 android 录音应用程序进行单元测试

[英]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.我只想知道是否可以使用 Robolectric 框架对 android 录音机应用程序进行单元测试。

As far as I know, Robolectric does not use the emulator or real device for testing.据我所知,Robolectric 不使用模拟器或真实设备进行测试。 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?它是否存储在 SD 卡上的指定位置? 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.我查看了许多 Robolectric 教程,但它们没有回答我的问题。 I had also asked this question(https://groups.google.com/forum/#!topic/robolectric/JLKrRGsvIkU ) in Robolectric google group which went unanswered.我也在 Robolectric 谷歌小组中问过这个问题(https://groups.google.com/forum/#!topic/robolectric/JLKrRGsvIkU ),但没有得到答复。 Is the concept of shadows helpful here?阴影的概念在这里有用吗?

I guess you use the MediaRecorder for recording audio.我猜您使用 MediaRecorder 来录制音频。

Robolectric has already a Shadow for the MediaRecorder. Robolectric 已经为 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详情见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.是的,您可以使用 Robolectric 对您的应用程序进行单元测试,但真正的录音将不起作用。 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.此外,使用 Espresso 等其他工具可能难以测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM