android 中最好的仪器测试框架是哪个?
Which is the best framework for instrumentation testing in android?
根据我的经验,单元测试有很多限制,例如要测试的 class 中的对象初始化。仪器测试是否优于单元测试?
两者各有千秋,您应该两者都用。
你应该尽可能地进行单元测试,并使用仪器测试来覆盖整个流程。
这实际上取决于您构建应用程序的方式,如果操作不正确,您将 运行 在尝试进行单元测试时遇到问题。
让我澄清一下你试图区分的是单元测试。
你可以比较一下 'Local/Small Unit Test vs Instrumented Unit Test.
Local/Small 单元测试基本上是针对数据模型的,您可能有 Android POJO 框架 dependency.Like 类。Local/Small 单元测试非常快,因为它不需要任何物理设备或模拟器到 运行。
由于 Instrumented Unit Testing 需要物理设备或模拟器,因此它比本地单元测试慢。
我想引用官方来源
Write small tests
As you add and change your app's functionality, make sure that these features behave as intended by creating and running unit tests against them. Although it's possible to evaluate units on a device or emulator, it's usually quicker and easier to test the units in your development environment, adding stubbed or mocked methods as needed to interact with the Android system.
Instrumented unit tests
You can also run instrumented unit tests on a physical device or emulator, which doesn't involve any mocking or stubbing of the framework. Because this form of testing involves significantly slower execution times than local unit tests, however, it's best to rely on this method only when it's essential to evaluate your app's behavior against actual device hardware.
更多详情请前往This
根据我的经验,单元测试有很多限制,例如要测试的 class 中的对象初始化。仪器测试是否优于单元测试?
两者各有千秋,您应该两者都用。
你应该尽可能地进行单元测试,并使用仪器测试来覆盖整个流程。
这实际上取决于您构建应用程序的方式,如果操作不正确,您将 运行 在尝试进行单元测试时遇到问题。
让我澄清一下你试图区分的是单元测试。
你可以比较一下 'Local/Small Unit Test vs Instrumented Unit Test.
Local/Small 单元测试基本上是针对数据模型的,您可能有 Android POJO 框架 dependency.Like 类。Local/Small 单元测试非常快,因为它不需要任何物理设备或模拟器到 运行。
由于 Instrumented Unit Testing 需要物理设备或模拟器,因此它比本地单元测试慢。
我想引用官方来源
Write small tests
As you add and change your app's functionality, make sure that these features behave as intended by creating and running unit tests against them. Although it's possible to evaluate units on a device or emulator, it's usually quicker and easier to test the units in your development environment, adding stubbed or mocked methods as needed to interact with the Android system.
Instrumented unit tests
You can also run instrumented unit tests on a physical device or emulator, which doesn't involve any mocking or stubbing of the framework. Because this form of testing involves significantly slower execution times than local unit tests, however, it's best to rely on this method only when it's essential to evaluate your app's behavior against actual device hardware.
更多详情请前往This