简体   繁体   English

物理设备上的 Android 单元测试实际上是一回事吗?

[英]Is Android unit testing on a physical device actually a thing?

Firebase has physical devices for testing: https://firebase.google.com/docs/test-lab/android/available-testing-devices however it's a little expensive. Firebase 有用于测试的物理设备: https://firebase.google.com/docs/test-lab/android/available-testing-devices但是它有点贵。

I was wondering if testing things on a physical Android device is a real thing and if there are frameworks for that.我想知道在物理 Android 设备上测试东西是否是真实的,是否有框架。 I know that there are unit tests that are mocked and run on the computer, but some things like the Android Media Codec Decoder can only be tested on the device我知道有单元测试是在计算机上模拟和运行的,但是像 Android Media Codec Decoder 这样的东西只能在设备上测试

Generally you write as much as you can as junit tests because running things on a real device is MUCH slower- both because the hardware is less powerful and due to the slowness of installing and launching an app on the USB connected device.通常,您尽可能多地编写 junit 测试,因为在真实设备上运行东西要慢得多 - 既是因为硬件功能不那么强大,也是因为在 USB 连接的设备上安装和启动应用程序的速度很慢。

That said, android does have instrumentation tests, which are unit tests that run on an Android device.也就是说,android 确实有仪器测试,这是在 Android 设备上运行的单元测试。 Generally you run them on emulators because its easier to set everything up, and to run it on a remote server.通常你在模拟器上运行它们,因为它更容易设置一切,并在远程服务器上运行它。 But you can run them on a physical device, you'd just need to have it attached to the machine running the test.但是你可以在物理设备上运行它们,你只需要将它连接到运行测试的机器上。 You just generally don't do it, unless you're testing a specific bug on a specific device.您通常不会这样做,除非您在特定设备上测试特定错误。

For your specific case- why can't you test the codec on an emulator?对于您的具体情况 - 为什么不能在模拟器上测试编解码器? The emulator should have it- its literally an Android OS running on a virtual machine.模拟器应该有它——它实际上是一个在虚拟机上运行的 Android 操作系统。 The only thing you can't really test on it is hardware, which isn't applicable here.唯一不能真正测试的是硬件,这里不适用。

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

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