-
Notifications
You must be signed in to change notification settings - Fork 2
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
test: fix tests for lower API levels #145
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
from
December 30, 2024 14:57
4f245ef
to
4f95624
Compare
matthiasemde
added
skip-ci
Skip the CI build in a PR
and removed
skip-ci
Skip the CI build in a PR
labels
Dec 30, 2024
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
from
January 1, 2025 18:20
77b8509
to
975fda4
Compare
matthiasemde
force-pushed
the
test/active-session
branch
from
January 3, 2025 20:16
9461638
to
fcf0d74
Compare
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
from
January 3, 2025 20:17
d94e3fa
to
266403b
Compare
matthiasemde
force-pushed
the
test/active-session
branch
from
January 3, 2025 20:45
fcf0d74
to
ea8648e
Compare
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
from
January 3, 2025 20:52
266403b
to
2e8fe6c
Compare
matthiasemde
force-pushed
the
test/active-session
branch
from
January 3, 2025 21:24
ea8648e
to
a7a1881
Compare
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
5 times, most recently
from
January 6, 2025 07:52
8276a23
to
0c0d714
Compare
mipro98
previously approved these changes
Jan 11, 2025
matthiasemde
force-pushed
the
test/active-session
branch
from
January 12, 2025 13:47
c0ef613
to
7f79008
Compare
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
from
January 12, 2025 13:47
0d2325f
to
d4651e0
Compare
matthiasemde
force-pushed
the
test/fix-tests-for-lower-api-levels
branch
from
January 12, 2025 16:13
73e9543
to
0db85e4
Compare
mipro98
approved these changes
Jan 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Story
This PR fixes issues for instrumented tests with lower API versions or disables them if no fix is available.
Disabling test
For disabling tests, we use the
@SdkSupress
decorator.Fixing test
Fixing test is a bit more difficult since many of the errors in the CI did not occur locally.
In an attempt to reproduce the CI environment on my machine and fix the tests, I migrated our test execution to gradle managed devices (god), introduced the AndroidX Test Orchestrator and built a screenshot on test failure feature which helps identify.
Gradle managed devices (gmd)
Using gradle managed devices, we can configure emulators inside our
build.gradle.kts
file which can then be used for testing. Both in the CI as well as locally. This improves reproducibility of CI test failures.If you want to use these devices for testing, you can use the automatically generated gradle tasks:
$ ./gradlew app:api29DebugAndroidTest
If you want to run only a specific test(-class) you can parameterize the call like this:
$ ./gradlew app:api29DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=app.musikus.library.presentation.LibraryScreenTest#addFolderOrItem_hintDisappears
AndroidX Test Orchestrator
The Android Test Orchestrator improves test stability by running each test in an independent instance of the application.
Screenshot on test failure
Findings and learnings
While fixing the
insertItems_checkSorting()
test inLibraryFolderDetailsScreenTest
I stumbled upon a nasty race condition involvingFakeTimeProvider.advanceTimeBy()
. When you i.e. create an object in the UI using theComposeRule
and advance the time right afterwards, the timestamp stored in the object can be either the old or the new timestamp depending on how fast the asynchronous execution of the object creation is running. This can result in multiple objects getting the same timestamp even though there is a call toFakeTimeProvider.advanceTimeBy()
in-between them.Helpful links