Disclaimer: just to make it clear, these notes are not quotes from the talk, it's my personal opinion and recommendations related to the things discussed in the Android Testing talk on the AndroidDevSummit and shown in the Android Testing Codelab.
1. Why mock backend in functional (UI) tests?
To prevent sharing the state of the backend between tests runs. It's not about preventing network issues.
Backends usually have state — DB, cache, etc. You probably won't be happy if your tests or tests runs will depend on each other.
2. How to mock backend in functional (UI) and integration tests?
Do not mock network via mocking the classes! Mock the server. MockWebServer will help you with that. Otherwise, you won’t test HTTP-layer, parsing, etc.
If you really want to mock backend via mocking the classes in functional (UI) tests then you should have a good set of integration tests.
3. How to use testing frameworks like Espresso?
Do not use test framework directly in your functional (UI) tests. Create Screen abstractions, etc and then use them in tests. Without such abstractions, your tests will be unmaintainable.
A little change of the UI can affect a lot of functional tests, you really want to refactor all of them each time?
4. Product flavors for tests? Not sure.
Product flavors really slow down the build both locally when you have to switch between them in IDE and on the CI. Also, they tend you to use flavor-specific
buildConfigFields in your
build.gradle which means that a lot of app's configuration options will be static.
Prefer dynamic app settings (base url of REST API and so on) then you'll be able to change behavior of the app without need in building and installing a different version.