π οΈ Refactoring for testability & adding test coverage #26
Replies: 2 comments
-
This is going to be more involved than expected, but this is a good thing (I think). Challenge #1: Hammerspoon is specialHammerspoon does not execute in the default
This means that leading test runners like
I'm currently leaning toward no. 1 because no. 2 is a ton of work, and I'd like to leverage some of the more generic Hammerspoon methods in tests (e.g., using Challenge #2: Stackline's design violates tons of best practices for testabilityI think Stackline's structure is generally sensible (that was the goal, anyway), but it's becoming increasingly clear that it's not very testable.
Much of this critique was inspired by this 11 year-old talk: Design Tech Talk Series Presents: OO Design for Testability. All of the talks in this series can be found at Google's Testing Blog. Much of the development time for the last couple of features (fuzzy frame detection and improved configuration) was spent chasing down collateral damage many levels removed from the actual change. Solving this puzzle & establishing a baseline of test coverage is now my top priority (before new features like displaying window titles and even before trying to solve irritating bugs such as swallowing all click events). Assuming that a pretty major refactor will be required to make testing possible presents a chicken-egg problem: I don't want to make changes without unit tests b/c it's hard to predict all the points of failure, and I need to make changes in order to add tests. The goal of this refactor is to make future features & changes easy-to-implement (with confidence that the change didn't break something else). |
Beta Was this translation helpful? Give feedback.
-
Here's a long overdue update on testing: Re: Challenge #1: Hammerspoon is specialI found something really interesting that unblocked this challenge: a handful of Hammerspoon modules can be required from a vanilla lua environment! Plus, the modules that work in a vanilla lua environment are the same modules that made mocking untenable (IMO):
In particular, the ability to require Check out the Hammerspoon mocks here https://github.com/AdamWagner/stackline/tree/tests/basic/spec/hammerMocks and feel free to use in personal projects. Also, I've been thinking about breaking this out into its own repo, but haven't done this yet to avoid dealing with git submodules. If anyone is interested in using Re: Challenge #2: Stackline's design violates tons of best practices for testabilityThe ability to mock out Hammerspoon modules enabled the use of Here's a visual and a coverage report: Coverage (2020-11-28)
|
Beta Was this translation helpful? Give feedback.
-
See
Beta Was this translation helpful? Give feedback.
All reactions