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

Add FXIOS-9680 [Unit Tests] Configure store to use var for testing builds #22070

Merged
merged 9 commits into from
Sep 23, 2024

Conversation

cyndichin
Copy link
Contributor

@cyndichin cyndichin commented Sep 18, 2024

📜 Tickets

Jira ticket
Github issue

💡 Description

Context
The store was a global constant that could not be mocked for unit testing. This causes testing issues especially within the middlewares. This PR allows us to overwrite the store and be able to verify logic such as a dispatch of an action or validating state in the store.

Summary

  • Added another build configuration called Fennec_Testing that duplicates the Fennec build, and adds an additional flag called TESTING under Custom Flags in the Build settings. This flag can be used to determine which code path to run. We want to have a var store instead of the let store in the testing case.
  • Also needed to add the flag under SWIFT_ACTIVE_COMPILATION_CONDITIONS
  • Updated the Fennec Scheme to use the Fennec_Testing build configuration when running tests
  • Change store to be a variable for testing build
  • Updated MicrosurveyMiddlewareTests to override the store

📝 Checklist

You have to check all boxes before merging

  • Filled in the above information (tickets numbers and description of your work)
  • Updated the PR name to follow our PR naming guidelines
  • Wrote unit tests and/or ensured the tests suite is passing
  • When working on UI, I checked and implemented accessibility (minimum Dynamic Text and VoiceOver)
  • If needed, I updated documentation / comments for complex code and public methods
  • If needed, added a backport comment (example @Mergifyio backport release/v120)

Screenshots

Compile errors example:
Screenshot 2024-09-18 at 3 07 13 PM

@FilippoZazzeroni FilippoZazzeroni force-pushed the cc/FXIOS-9680_update-store-to-be-testable branch from e3f0ccd to da7e1c8 Compare September 19, 2024 17:58
@cyndichin
Copy link
Contributor Author

@clarmso Bitrise is failing, we are thinking this is because we are using the Fennec configuration. Could we update the configuration to use Fennec_Testing instead for this PR + future PRs if this decide to land?

cc: @FilippoZazzeroni

@cyndichin cyndichin force-pushed the cc/FXIOS-9680_update-store-to-be-testable branch from f97f97a to 05b62c7 Compare September 19, 2024 19:39
@mobiletest-ci-bot
Copy link

mobiletest-ci-bot commented Sep 19, 2024

Messages
📖 Project coverage: 31.24%
📖 Edited 6 files
📖 Created 1 files

Client.app: Coverage: 29.75

File Coverage
AppState.swift 100.0%

Generated by 🚫 Danger Swift against 368fee1

@cyndichin
Copy link
Contributor Author

@FilippoZazzeroni It's passing, I'm crying with happy tears~ 🥳

@cyndichin cyndichin marked this pull request as ready for review September 19, 2024 20:13
@cyndichin cyndichin requested review from a team as code owners September 19, 2024 20:13
)
}

private func setupTestingStore() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks good to me, i don't know only for later tests, if we want to add an Utility class to make a custom store and to restore it to default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @FilippoZazzeroni! Yes, you're right, I agree. I created a separate ticket for this though since I prefer to break up work in smaller chunks: https://mozilla-hub.atlassian.net/browse/FXIOS-10094

I'll probably also get the teams input on the best way to go about this since want to make sure that its clear down the row that this is something we need to do for testing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect thank you Cyndi, yes that is top.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed that the setup and teardown of store will be cleaned up in a future PR and that work will go in FXIOS-10094 as we think about a better way to setup and teardown the stores.

@cyndichin
Copy link
Contributor Author

@isabelrios @clarmso seems like this PR needs a review from your side as well, let me know if any issues! thank you~

@clarmso
Copy link
Collaborator

clarmso commented Sep 23, 2024

@cyndichin 👍🏼 Let's see how this scheme behaves. If there are any issues, I will let you know.

@cyndichin cyndichin merged commit eb53b79 into main Sep 23, 2024
13 checks passed
@cyndichin cyndichin deleted the cc/FXIOS-9680_update-store-to-be-testable branch September 23, 2024 22:17
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.

4 participants