You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
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:
UserDefaults
instead of accessing.standard
.protocol
s to place between domain object andUserDefaults
UserDefaults
state before and after each test that interacts with itShameless 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.The text was updated successfully, but these errors were encountered: