[unit tests] Add some infrastructure for OneSignalCore and OneSignalUser#1371
Merged
[unit tests] Add some infrastructure for OneSignalCore and OneSignalUser#1371
OneSignalCore and OneSignalUser#1371Conversation
Looks like these methods are no longer used within the SDK, so let's remove them from OneSignalClient: - executeSimultaneousRequests - executeSynchronousRequest - executeDataRequest Update OneSignalClient.h And types: - OSDataRequestSuccessBlock - OSMultipleCompletionBlock - OSMultipleFailureBlock - OSMultipleSuccessBlock - genericTimedOutError
- Make a OneSignalCore class through which the services of this module can be set and accessed - To start, make a protocol for OneSignalClient, IOneSignalClient (name of protocol TBD)
- Change all `OneSignalClient.sharedClient` calls to `OneSignalCore.sharedClient`
* Store in the variable `POLL_INTERVAL_MS` so that it can have a different value for testing vs non-testing
OneSignalCore and OneSignalUser
* Add mocking framework called `OneSignalCoreMocks` to simplify working with `OneSignalCore` in unit tests
- Add helper method `clearUserDefaults()`
- Create `MockOneSignalClient` class to replace `OneSignalClient` in unit tests
* Add mocking framework called `OneSignalUserMocks` to simplify working with `OneSignalUser` in unit tests
- Add some helper methods to reset state between tests, WIP
* Add unit testing bundle `OneSignalCoreTests`, meant to test `OneSignalCore`
- Add one test `testNotificationJson`, to get started
* Add unit testing bundle `OneSignalUserTests`, meant to test `OneSignalUser`
- Add one test `testLoginSetsExternalId`, to get started
* Delete old "user model" test files `UserModelObjcTests.m and `UserModelSwiftTests.swift`
- These weren't real tests
2e215b4 to
d6102b4
Compare
* We want to use force casts in testing
emawby
approved these changes
Feb 16, 2024
Contributor
Author
|
The CI succeeded at first because it was only testing the tests in UnitTests module (which includes 0 tests). We are trying to make all testing bundles run, so we added UserTests and CoreTests to the UnitTestApp scheme. However, after that change, now the CI is failing. |
2db39b3 to
4f30fe0
Compare
* Missed adding this
4bfcb1e to
a7c1143
Compare
- ENABLE_TESTABILITY in OneSignalUserTests and OneSignalCoreTests modules updated to match existing UnitTests - UnitTestApp scheme updated to include OneSignalUserTests and OneSignalCoreTests test modules - Now, the CI runs all tests automatically!
78158a4 to
194832e
Compare
Contributor
Author
|
The CI now passes, and runs all the testing bundles, UnitTests, OneSignalCoreTests.xctest, and OneSignalUserTests.xctest. |
18 tasks
This file contains hidden or 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
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.
Description
One Line Summary
Rebuilding our unit tests by adding basic infrastructure to work with the modules
OneSignalCoreandOneSignalUser.Details
1. (cleanup) Removed some unused things from the
OneSignalClient2. Make
OneSignalCoreclass to set and access module's servicesOneSignalClient, calledIOneSignalClient(open to more ios-appropriate name for the protocol)OneSignalClient.sharedClientbut if unit tests set their own client, return that one3. Now, access the client via OneSignalCore
OneSignalClient.sharedClientcalls toOneSignalCore.sharedClient4. Extract Operation Repo's poll interval into a constant
POLL_INTERVAL_MSso that it can have a different value for testing vs non-testing5. Add 2 mocking frameworks and 2 testing bundles
OneSignalCoreMocksto simplify working withOneSignalCorein unit testsclearUserDefaults()MockOneSignalClientclass to replaceOneSignalClientin unit testsOneSignalUserMocksto simplify working withOneSignalUserin unit testsOneSignalCoreTests, meant to testOneSignalCoretestNotificationJson, to get startedOneSignalUserTests, meant to testOneSignalUsertestLoginSetsExternalId, to get started6. (cleanup) Delete old "user model" test files
UserModelObjcTests.mandUserModelSwiftTests.swift7. Add separate swiftlint file for test modules to allow force casts
Motivation
Rebuilding unit tests
Scope
Testing
Unit testing
Manual testing
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is