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

Decouple from UserDefaults.standard in tests #18778

Open
mokagio opened this issue May 31, 2022 · 1 comment
Open

Decouple from UserDefaults.standard in tests #18778

mokagio opened this issue May 31, 2022 · 1 comment
Assignees
Labels
Testing Unit and UI Tests and Tooling [Type] Task

Comments

@mokagio
Copy link
Contributor

mokagio commented May 31, 2022

A recent issue in the tests and @dvdchr's workaround for it make it clear that we have some state leaking into UserDefaults.standard and affecting the unit tests.

This ought not to happen. There are various ways to tackle this problem. For example:

  • Inject an in-memory UserDefaults instead of accessing .standard.
  • Use Dependency Inversion, defining one or more protocols to place between domain object and UserDefaults
  • Dup and restore the UserDefaults state before and after each test that interacts with it

Shameless plug, see Test-Driven Development in Swift, Chapter 15.

Before picking one, we should spend some time inspecting the codebase for UserDefaults accesses. I wouldn't be surprised if more than one approach will be necessary, depending on the complexity level of different consumers.

@dangermattic
Copy link
Collaborator

dangermattic commented Dec 20, 2024

Thanks for reporting! 👍

@kean kean removed the [Type] Core label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing Unit and UI Tests and Tooling [Type] Task
Projects
None yet
Development

No branches or pull requests

3 participants