Skip to content
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

LD-124 Add robolectric tests support #142

Merged
merged 19 commits into from
Oct 16, 2023
Merged

LD-124 Add robolectric tests support #142

merged 19 commits into from
Oct 16, 2023

Conversation

jacek-marchwicki
Copy link
Member

@jacek-marchwicki jacek-marchwicki commented Oct 12, 2023

Description

Why?

androidTests are very useful, they are executed on real devices and those tests ensures that app works on user devices. Unforuntelly those tests are slow to execute. Running the full test suite takes time, and requires having emulator.
There is an alternative for androidTests wich is Robolectric tests. Those tests uses the same espresso/androidx test framework, but are executed on local machine, not on device. Those tests are much faster.

androidTest robolectric test unit tests
👎🏾 very slow 👍🏾 faster 👍🏾 fastest
👎🏾 expensive to run 👍🏾 inexpensive 👍🏾 inexpensive
👍🏾 checks on real device 👍🏾👎🏾simulate android environment 👎🏾 run only on mocks
👍🏾 runs the whole app on real device 👍🏾👎🏾 runs the whole app on simulated device 👎🏾 only checks part of the code
👎🏾 don't track the root of the problem 👎🏾 don't track the root of the problem 👍🏾 find the root of the problem
👎🏾 Flaky 👎🏾👍🏾 a little bit flaky 👍🏾 usually not flaky

What problems can be detected by given test suite

Problem androidTest robolectric unit tests
Bitmap causes OutOfMemoryException  ✅
Issue in a certain android version  ✅ ❌ / ✅
There is a problem in app initialization  ✅
Problems related to other apps  ✅
Problems with communication to a backend  ✅
Activity initialization problem  ✅
Issue in android OS  ✅
Specific case/problem in a single class  ❌
Issues with progard ❌*

This leads to conclustions, that we have a piramide of test suite, that no of tests looks like this:

flowchart TD
    A[Unit Tests] -->|Less tests| B[Robolectric Tests] --> |Less tests| C[Android Tests] --> |Less tests| D[End To End Tests]
Loading

What is greatest is that Robolectric and Android Tests uses the same framework for testing which mean, we can write the same test once and run them once with Robolectric framework, once with Android Emulator.
I.e. for quick feedback, after developing a feature with a test. We can firstly ensure that given test runs in Robolectric environemnt with very quick feedback loop. Then run it on Android Emulator for a little bit slower feedback loop. Then Run the whole Robolectric test suite on our machine for quick feedback loop of the whole test suite. After this, we can push to CI to run the while test suite on Android Emulators to ensure if there is no regression on real devices.

What?

  • Added Robolectric framwork
  • Set-up common space for Robolectric and Android Tests.
  • Prepared set-up that allows running given test with Robolectric and Android Test mode.
  • Migrated all Android Tests to Robolectric/Android tests
  • Changed syncrhonization from AndroidComposeTestRule.registerIdlingResource which is not supported by robolectric to waitUntil syncrhonization waitUntil
  • Ensured all tests are executed on CI
  • Created failed CI tests report available on GitHub https://github.com/appunite/Loudius/pull/142/checks?check_run_id=17675255175

Links to related issues

Documentation

Notes

Robolectric doesn't support AndroidComposeTestRule.registerIdlingResource so we need to wait differently for loading to finish.

Checklist

  • Functionality covered by unit tests
  • I have manually tested if the code works

@github-actions
Copy link

Snapshot testing result: ✔️
Everything looks good!

@github-actions
Copy link

github-actions bot commented Oct 12, 2023

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ ACTION actionlint 1 0 0.12s
✅ COPYPASTE jscpd yes no 3.51s
✅ KOTLIN ktlint 33 0 0 79.7s
✅ REPOSITORY checkov yes no 19.44s
✅ REPOSITORY devskim yes no 1.04s
✅ REPOSITORY dustilock yes no 0.29s
✅ REPOSITORY gitleaks yes no 1.23s
✅ REPOSITORY git_diff yes no 0.04s
✅ REPOSITORY secretlint yes no 2.4s
✅ REPOSITORY syft yes no 0.48s
✅ SPELL misspell 37 0 0 0.11s
✅ XML xmllint 2 0 0 0.06s
✅ YAML prettier 1 0 0 0.87s
✅ YAML v8r 1 0 2.56s
✅ YAML yamllint 1 0 0.35s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@jacek-marchwicki
Copy link
Member Author

@nowakweronika

@jacek-marchwicki jacek-marchwicki marked this pull request as ready for review October 13, 2023 11:58
Copy link
Collaborator

@nowakweronika nowakweronika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jacek-marchwicki jacek-marchwicki merged commit 61ed4dd into develop Oct 16, 2023
19 checks passed
@jacek-marchwicki jacek-marchwicki deleted the robolectric branch October 16, 2023 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants