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

CI - Fix failing test 2024-02-14; Includes fixes for RobolectricTest, updating to Android compile API 34, and fixing a variety of tests #1994

Merged
merged 17 commits into from
Feb 27, 2024

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Feb 14, 2024

Description

One Line Summary

Fix failing tests and test improvements; including fixing silently skipped tests due to RobolectricTest issues and android versions.

Details

The main focus of the PR was to fix unit tests using @RobolectricTest being skipped and fixing any failing tests. This was done by making changes to RobolectricExtension. Some other changes are:

  • De-duplicating RobolectricExtension by adding a new testhelpers module to share this class
  • Updating Android compile and target versions
  • Fixed location tests failing due to Java 17 version upgrade (from PR CI - Switch to android-actions/setup-android@v3 #1992)
  • Fix a variety of tests

Motivation

It's important to keep our CI test works and up to date to catch bugs early.

Scope

Only fixing testing related issues.

Reviewing

Recommend reviewing commit-by-commit

Testing

Unit testing

All Unit Tests are now passing

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

Base automatically changed from ci/fix-ktlint-errors-2024-02-14 to main February 15, 2024 18:42
@jkasten2 jkasten2 force-pushed the ci/fix-unit-tests-2024-02-14 branch 2 times, most recently from ec15313 to 174a7ca Compare February 15, 2024 21:38
This fixes an error compile tests for in-app messages.
androidx.work:work-runtime-ktx:2.8.1 was interduced and it requires
android compile SDK version 33.
Replaced ShadowFusedLocationProviderApi with
FusedLocationApiWrapperMock as it depended on
Field::class.java.getDeclaredField("modifiers") which was a reflection
feature dropped in somewhere between Java 11 -> 17.

Since there wasn't a straightforward way to keep this as a shadow it
was worth the time instead to use dependency inject.
PR #1900 intorduced FAIL_PAUSE_OPREPO but never updated the test
PR #1794 made changes to omit aliases on user create, but the test was
never updated. Also the SubscriptionStatus arg part of this test wasn't
compare the corret types, causing it to fail the test.
It seems Kotest's intercept caller eats expections and moves on
silently. Adding a try-catch and reporting TestResult.Error to solve
this.
The first class with @RobolectricTest would run fine, but then every
test class after in the run would fail with a looper already started
error.

This fix was discovered by looking through Robolectric's
RobolectricTestRunner and SandboxTestRunner clases. Most of the
pre-existing kotest-extensions-robolectric code seemed to be reripped
from those 2 classes and I notice this was something this extension was
not doing. Looper's are linked to a thread so this seems related,
however I don't understand any more than this to explain why this fixes
the error.
De-duplicated ContainedRobolectricRunner.kt and RobolectricExtension.kt
by moving them into their own module.

Before landing on this implementation I attempted to use the gradle
feature testFixtures, however this doesn't work with the android
gradle plugin.
This makes sure you can see all failures
Test were being run 3 times since it was running debug, release, and
unity targets.
@jkasten2 jkasten2 changed the title WIP - CI - Fix unit tests 2024-02-14 CI - Testing infrastructure fixes Feb 21, 2024
@jkasten2 jkasten2 changed the title CI - Testing infrastructure fixes CI - Testing infrastructure fixes; Most @RobolectricTest Feb 21, 2024
@jkasten2 jkasten2 requested review from brismithers, jennantilla, nan-li and emawby and removed request for brismithers February 21, 2024 06:09
@jkasten2 jkasten2 assigned jkasten2 and nan-li and unassigned jkasten2 Feb 21, 2024
@jkasten2 jkasten2 changed the title CI - Testing infrastructure fixes; Most @RobolectricTest CI - Testing infrastructure fixes; Mostly @RobolectricTest Feb 21, 2024
In a previous commit I assumed all 4 copies of RobolectricExtension.kt
were the same, however there was a difference in their getConfig
implementation.

This fixes a number of failing tests, such as the location tests.
id isn't a valid parameter to the OneSignal POST /subscriptions REST API
Test was out-of-date to the production changes we made a while ago.
This was the only test failing in this file and now it is passing.
Update allways follow from the module to resulting in making a network
request to reflect it on the backed. An update operation will never
result in property update to the model. This was proabably true at one
point the code base, but if so it was a mistake.
If we get a 404 when we try to delete then it was already done at
some point, so we count it as successful
@jkasten2 jkasten2 changed the title CI - Testing infrastructure fixes; Mostly @RobolectricTest CI - Fix failing test 2024-02-14; Includes fixes for RobolectricTest, updating to Android compile API 34, and fixing a variety of tests Feb 22, 2024
@@ -25,3 +25,4 @@ include ':OneSignal:core'
include ':OneSignal:in-app-messages'
include ':OneSignal:location'
include ':OneSignal:notifications'
include ':OneSignal:testhelpers'
Copy link
Contributor

Choose a reason for hiding this comment

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

Having this here doesn't affect SDK consumers?

Copy link
Member Author

@jkasten2 jkasten2 Feb 27, 2024

Choose a reason for hiding this comment

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

Right, the include in the setting.gradle is just to define projects are available to the workspace:
https://www.baeldung.com/gradle-build-settings-properties#settings-gradle

@@ -171,13 +171,15 @@ class OutcomeEventsRepositoryTests : FunSpec({
OutcomeEventsTable.COLUMN_NAME_NAME to "outcomeId1",
OutcomeEventsTable.COLUMN_NAME_WEIGHT to 0.2f,
OutcomeEventsTable.COLUMN_NAME_TIMESTAMP to 1111L,
OutcomeEventsTable.COLUMN_NAME_SESSION_TIME to 1L,
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting this column was added in #1793

@jkasten2 jkasten2 merged commit a54c5c6 into main Feb 27, 2024
2 checks passed
@jkasten2 jkasten2 deleted the ci/fix-unit-tests-2024-02-14 branch February 27, 2024 19:15
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