HACKER Q&A
📣 pdappollonio

Any suggestion on how to test CLI applications?


Hello HN!

I've been looking at alternatives on how to test command line applications, specifically, for example, exit codes, output messages and whatnot. I've seen "bats" https://github.com/sstephenson/bats and Bazel for testing but I'm curious as what other tools people use in a day to day basis. UI testing is nice with tools like Cypress.io and maybe there's something out there that isn't as popular but it's useful.

Thoughts?


  👤 westurner Accepted Answer ✓
pytest-docker-pexpect: https://github.com/nvbn/pytest-docker-pexpect

Pexpect: https://pexpect.readthedocs.io/en/stable/

pytest with subprocess.popen (or Sarge) may be sufficient for checking return codes and checking stdout and stderr output streams. Pytest has tmp_path and tmpdir fixtures that provide less test isolation than Docker containers: http://doc.pytest.org/en/latest/tmpdir.html

sarge.Capture.expect() takes a regex and returns None if there's no match: https://sarge.readthedocs.io/en/latest/tutorial.html#looking...


👤 verdverm
https://github.com/sstephenson/bats sstephenson/bats: Bash Automated Testing System - GitHub

👤 bryanrasmussen
If you like Cucumber https://github.com/cucumber/aruba