Unit-testing a console app
jmmv.dev
jmmv.dev
(I'd favour command-line over console to avoid any possible confusion with games consoles.)
As it's pretty vital information I don't think it belongs in a subheading, which may be chopped when the post is submitted to a site like HN.
> any CLI that asks for user input on a line-oriented manner (e.g. a REPL) would qualify, right?
That's true, but it's more specific than console app. It would be a bit cumbersome to restate what TUI means in less obscure terms, although it wouldn't be the longest title known to man: Unit-testing a full-screen interactive command-line application.
That was not good not clear, as there are command line text editors like ed.
https://en.wikipedia.org/wiki/Ed_(text_editor)
Another way to disambiguate TUIs vs CLIs is to refer to the frameworks used to develop the app. For instance, mentioning ncurses or ncurses-based app is also frequently used to refer to TUIs.
It's pretty common when referring to text-based user interfaces, and when there's a clear distinction between a basic command line application.
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