Best practices for Android Unit Testing?

前端 未结 3 1983
囚心锁ツ
囚心锁ツ 2021-02-04 03:48

I am developing a mobile android app. What are the most common libraries/frameworks used for Android unit testing? I feel that most of the business logic, database testing, Web

相关标签:
3条回答
  • 2021-02-04 04:09

    I use JUnit for unit testing and Robolectric for instrumentation tests.

    This article shows you a Hello World example with Robolectric

    In recent times, I have been researching about integration testing in Android using Arquillian Droidium.

    If you want to test some code that consumes a REST API, you can mock it with WireMock. With this library, you can mock REST APIs by code or even deploy a mock HTTP server in your own machine and set up your own mocked mappings.

    For REST API mocks, I also recommend you to use Mockable.io.

    0 讨论(0)
  • 2021-02-04 04:22

    There is a guide for automated user interface testing on the Android Developers Website. I haven't tried it but it looks like what you've been looking for.

    0 讨论(0)
  • 2021-02-04 04:26

    2017 answer

    The Android documentation has a topical series called Best Practices for Testing. I would start there.

    Local Unit Tests and Instrumented Tests are set up by default when you start a new project. The general advice given is to use the local unit tests whenever possible. Sometimes this requires mocking an object that uses the Android API. The documentation recommends using Mockito in these cases. When UI tests (instrumented tests) need to be done, Android provides the Espresso framework. There are also other tools available, like the Exerciser Monkey (for stress testing) and UI Automator (for testing multiple app interaction).

    Example

    See this answer for how to get started with tests in Android Studio.

    0 讨论(0)
提交回复
热议问题