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

Preferences being a singleton makes it hard to run hermetic tests #294

Open
lukhnos opened this issue Feb 16, 2022 · 1 comment
Open

Preferences being a singleton makes it hard to run hermetic tests #294

lukhnos opened this issue Feb 16, 2022 · 1 comment

Comments

@lukhnos
Copy link
Contributor

lukhnos commented Feb 16, 2022

I wonder if we should consider making Preferences an instantiable class, and the input method app should instantiate with the user defaults back store, whereas tests can instantiate with an empty dictionary. We now have quite some test code that does this:

let someSavedState = Preferences.someKey
// do the test
Preferences.someKey = someSavedState

PR #293 also needs to do this in Plain BPMF test's setup and teardown due to punctution handling is coupled with keyboard layout. Interestingly, KeyHandler by default does not depend on it; it only reads from Preferences when InputMethodController tells it to sync with the prefs; but punctuaction handllers need to eagerly read the keyboard layout value…

@zonble
Copy link
Contributor

zonble commented Feb 16, 2022

I guess we can extract a DTO from the preferences and then put it into KeyHandlerInput, so the key handler can just depends on the input data but no other dependencies.

Actually I've already put the flag to use vertical candidate in KeyHandlerInput.

lukhnos added a commit that referenced this issue Nov 23, 2023
This issue was discovered after #381 if the tests were run locally when
`selectCandidateWithNumericKeypad` is set to true. This makes the test
reset and restore the setting during testing.

Ideally we shouldn't let Preferences affect tests, since they are
supposed to be hermetic. We have discussed the issue in #294. Until the
code is properly refactored, though, this will make the tests pass
locally.

Also updated the reset-restore code elsewhere in the tests so that the
restore always takes place before the assertions.
lukhnos added a commit that referenced this issue Nov 23, 2023
This issue was discovered after #381 if the tests were run locally when
`selectCandidateWithNumericKeypad` is set to true. This commit makes the
test reset and restore the setting during testing.

Ideally we shouldn't let Preferences affect tests, since they are
supposed to be hermetic. We have discussed the issue in #294. Until the
code is properly refactored, though, this will make the tests pass
locally.

Also updated the reset-restore code elsewhere in the tests so that the
restore always takes place before the assertions.
zonble pushed a commit to zonble/McBopomofo that referenced this issue Nov 26, 2023
This issue was discovered after openvanilla#381 if the tests were run locally when
`selectCandidateWithNumericKeypad` is set to true. This commit makes the
test reset and restore the setting during testing.

Ideally we shouldn't let Preferences affect tests, since they are
supposed to be hermetic. We have discussed the issue in openvanilla#294. Until the
code is properly refactored, though, this will make the tests pass
locally.

Also updated the reset-restore code elsewhere in the tests so that the
restore always takes place before the assertions.
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

No branches or pull requests

2 participants