wordpress-mobile / wordpress-mobile/WordPress-iOS

Decouple from `UserDefaults.standard` in tests

Open
#18,778 1 comment 1 reaction 1 assignee View on GitHub

@mokagio is already working on this.

Since May 31, 2022.

[Type] Task Testing
Dominant language
Swift
Stars
3.9k
Forks
1.2k
Avg merge
23h 51m
Merged PRs (30d)
58

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.