#CLI Unit Testing Recommendations
4 messages · Page 1 of 1 (latest)
your application logic should be entirely separated from whatever actually interacts with it (EG. CLI or REST API, or gRPC etc). By separating your core logic, you can make it testable, and also expandable if you want to add more ways to interact with it in the future
I assume you're after testing of your application logic, and not testing the CLI code which should just be parsing config from whatever sources (env vars, flags, etc) and calling your application logic
Have a look at https://bitfieldconsulting.com/posts/test-scripts for testing cli behavior (I use a fork of testscript to test my CLIs e2e, doesn’t replace unit tests of main logic as mentioned but is also useful (I don’t use cobra though but it should work)