44 points · by jmmv · 5y ago · 18 comments
It's pretty common when referring to text-based user interfaces, and when there's a clear distinction between a basic command line application.
(I'd favour command-line over console to avoid any possible confusion with games consoles.)
In an effort to make it more portable I have started a re-write[1] in Rust (using `crossterm` this time). This mocking strategy seems like exactly what I need to fix this gap in the app's tests.
https://github.com/ryanrodemoyer/writing_testable_code
I created a cheesy pneumonic device to help remember the four principles.
La.S.I.C.
1. Loosely couple your code from the entry point.
* Entry points are consoles, apis, services, GUI's, etc.
* The entry point always performs some type of setup or initialization.
2. Simultaneously write code and write test. * Will quickly discover what designer patterns are easy to easy, and which suck to test.
3. Isolate dependencies using classes and interfaces. * Use classes and interfaces to abstract/isolate/wrap away behavior with dependencies.
4. Constructors are for declaring dependency needs, not initialization![0] - https://github.com/tstack/lnav/blob/master/test/scripty.cc