-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review of practices #30
base: main
Are you sure you want to change the base?
Changes from all commits
6e0b591
f94a984
166d8d7
1fb3bf5
88d0741
497d515
2f24e61
1815a54
3e9b9aa
eab7416
c7f7570
8124fa0
3398f94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# Emulator setup | ||
|
||
Basically we have next choices: | ||
Basically we have 2 choices: | ||
|
||
* Manage devices automatically by `avd` | ||
* Manage docker containers with emulators by `docker` | ||
* Manage devices automatically via `avd` | ||
* Manage docker containers with emulators with `docker` | ||
|
||
Using docker image is the easiest way, however it's important to understand how docker creates device for you. | ||
Using a docker image is the easiest way, however it's important to understand how docker creates emulators for you. | ||
|
||
## Creating an emulator | ||
|
||
Before starting to read this topic, make sure you've read | ||
an [an official documentation](https://developer.android.com/studio/run/emulator-commandline) | ||
Before starting to read this, make sure you've read | ||
[the official documentation](https://developer.android.com/studio/run/emulator-commandline) | ||
|
||
Firstly, you need to create an `ini` configuration: | ||
Firstly, you need to create an `ini` configuration file for the emulator: | ||
|
||
```ini | ||
PlayStore.enabled=false | ||
|
@@ -48,19 +48,19 @@ skin.name=320x480 | |
disk.dataPartition.size=8G | ||
``` | ||
|
||
Pay your attention that we disabled: | ||
Pay attention to what we have disabled: | ||
|
||
* Accelerometer | ||
* Audio input/output | ||
* Play Store | ||
* Sensors:Accelerometer, Humidity, Pressure, Light | ||
* Gyroscope | ||
|
||
We don't really need them for our tests run. It also may improve our tests performance, because there are no background | ||
operations related to that tasks. | ||
We don't really need them for our test runs. It also may improve our tests performance, because there are no background | ||
operations related to those tasks. | ||
|
||
After that, you can run your emulator by `avd manager`, which is a part of android sdk manager. After your device | ||
creation, you need change default generated ini file to custom one. You may see an example below: | ||
After that, you can run your emulator via `avd manager`, which is part of the android sdk manager. After creating the emulator, you need to switch the default generated `ini` file to the custom one we defined previously. | ||
You can achieve that with a script like this one: | ||
|
||
```bash | ||
function define_android_sdk_environment_if_needed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly recommend to have a "ready" bash file for this that we upload in this article (maybe extra subsection here to make it more prominent) and indicate how to execute -> |
||
|
@@ -109,22 +109,28 @@ define_path_environment_if_needed | |
create_and_patch_emulator | ||
``` | ||
|
||
Pay your attention that you also need to wait until your emulator is fully booted. | ||
Keep in mind that the emulator must fully boot before running any test. Otherwise the tests will fail because there is still no device ready | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, for snapshot testing I was using swarmer from Juno, which is deprecated but works pretty fine for starting several emulators and wait for all of them to be ready before running the tests. Maybe worth mentioning later, after releasing the MVP? |
||
on which they can run. | ||
|
||
## How to run an emulator in a Docker? | ||
### Summary | ||
1. create an `ini` configuration file for the emulator | ||
2. run your emulator via `avd manager` and | ||
3. switch the `ini` file generated in 2. with the one we create in 1. | ||
|
||
Running an emulator in a docker a way easier than manually, because it encapsulates all this logic. If you don't have an | ||
experience with docker, you can check | ||
[this guide](https://www.youtube.com/watch?v=zJ6WbK9zFpI) to check the basics. | ||
## How to run an emulator in Docker? | ||
|
||
There are some popular already built docker images for you: | ||
Running an emulator in a docker is way easier than manually, because it encapsulates all this logic. If you don't have | ||
experience with docker, check | ||
[this guide](https://www.youtube.com/watch?v=zJ6WbK9zFpI) to get familiarized with the basics. | ||
|
||
There are some popular docker images already built for you: | ||
|
||
* [Official Google emulator](https://github.com/google/android-emulator-container-scripts) | ||
* [Agoda emulator](https://github.com/agoda-com/docker-emulator-android) | ||
* [Avito emulator](https://hub.docker.com/r/avitotech/android-emulator-29) | ||
|
||
Talking about [Avito emulator](https://github.com/google/android-emulator-container-scripts), it also patches your | ||
emulator with adb commands to prevent tests flakiness and to speed them up | ||
Talking about the [Avito emulator](https://github.com/google/android-emulator-container-scripts), it also patches your | ||
emulator with adb commands to prevent tests flakiness and to speed them up. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be good to quickly mention how it does it. What are the differences among them? As a learner, I want to use the best for my needs |
||
|
||
##### Run Avito emulator | ||
|
||
|
@@ -154,18 +160,18 @@ docker rm $(docker ps -a -q) | |
## Conclusion | ||
|
||
* Use docker emulators </br> | ||
_You also will have an opportunity to run them with `Kubernetes`, to make it scalable in the future_ | ||
_You'll also have the opportunity to run them with `Kubernetes`, to make it scalable in the future_ | ||
|
||
* Start fresh emulators each test batch and kill them after all of your tests finished</br> | ||
_Emulators tend to leak and may not work properly after some time_ | ||
* Start fresh emulators on each test batch and kill them after all of your tests finished</br> | ||
_Emulators tend to freeze and may not work properly after idling for some time_ | ||
|
||
* Use the same emulator as on CI locally</br> | ||
* Use the same emulator locally as on your CI </br> | ||
_All devices are different. It can save you a lot of time with debugging and understanding why your test works locally | ||
and fails on CI. It won't be possible to run Docker emulator on macOS or Windows, because | ||
and fails on CI. It won't be possible to run Docker emulators on macOS or Windows, because | ||
of [haxm#51](https://github.com/intel/haxm/issues/51#issuecomment-389731675). Use AVD to launch them on such | ||
machines (script above may help you)_ | ||
|
||
!!! warning | ||
|
||
To run an emulator on CI with a docker, make sure that nested virtualisation supported and KVM installed. | ||
To run an emulator on CI with a docker, make sure that nested virtualisation is supported and KVM is installed. | ||
You can check more details [here](https://developer.android.com/studio/run/emulator-acceleration#vm-linux) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
# Emulator vs Real device | ||
|
||
This question is a trade off and there is no right and wrong answers. We'll review pros/cons and basic emulator setup on | ||
CI | ||
Instrumented tests can run either on emulators or real devices. Which one should we used? | ||
This question is a trade off and there is no right or wrong answer. We'll review the pros and cons of both approaches. | ||
|
||
## Real device | ||
|
||
Here is pros/cons | ||
Here the pros/cons | ||
|
||
➕ Real environment </br> | ||
➕ Doesn't consume CI resources | ||
➕ Doesn't consume significant RAM, CPU and memory of the CI. | ||
|
||
➖ Breaks often </br> | ||
➖ Requires special conditions </br> | ||
➖ Breaks often: Battery swells, USB port failures, OS software failing... all this happens because real devices are not designed to be intensively used continuously. </br> | ||
➖ Requires to place them in a room with special environment conditions </br> | ||
|
||
A real device will help you to catch more bugs from the first perspective, however talking about scalability, if you | ||
Although it seems that a real device is a better alternative because it helps you catch bugs on a full-fledged Android environment, it comes with its own issues. However, talking about scalability, if you | ||
have a lot of devices, you need to locate them in a special room with no direct sunlight and with a climate-control. | ||
|
||
However, it doesn't save from disk and battery deterioration, because they are always charging and performs I/O | ||
operations. It may be a reason of your tests failing not because of them caught a real bug, but because of an issue with | ||
a device. | ||
But that doesn't prevent them from disk and battery deterioration, because they are always charging and performing I/O | ||
operations. Therefore, if your tests fail, could be because of an issue with | ||
a device and not because of a real bug in the app under test. | ||
|
||
## Emulator | ||
|
||
Here is pros/cons | ||
Here the pros/cons | ||
|
||
➕ Easy configurable </br> | ||
➕ Can work faster than a real device </br> | ||
➕ Can work faster than a real device</br> | ||
_Keep in mind that it's achievable only if you applied a special configuration and have powerful build agents_</br> | ||
➕ Тot demanding in maintenance </br> | ||
➕ Not demanding in hardware maintenance e.g. battery, disk, USB ports, display...) </br> | ||
|
||
➖ Not a real environment </br> | ||
➖ Consumes CI resources </br> | ||
➖ Not the real environment on which the app will end up running</br> | ||
➖ Consumes significant resources of the CI like RAM, CPU and memory</br> | ||
➖ Emulators might freeze if stay idle for a long time and need to be restarted.</br> | ||
|
||
The most benefit that we may have is a fresh emulator instance each test bunch. Also, it's possible to create a special | ||
configuration and disable features you don't need to have in tests which affects device stability. However, you need to | ||
have powerful machine (and definitely not one, if you want to run your tests on pull requests) | ||
The main benefit that we may have is a fresh emulator instance on each test run. Also, it's possible to create a special | ||
configuration and disable features you don't need to have in tests, like sensor or audio input/output, which affect device stability. Nevertheless, you need | ||
a powerful machine (and definitely not one, if you want to run your instrumented tests on very pull requests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rephrased this. I believe this is what is intended after reading the code in the script