assert-rs / assert_cmd

Assert process::Command - Easy command initialization and assertions
https://docs.rs/assert_cmd
Apache License 2.0
462 stars 34 forks source link

Some help with getting started #162

Open fritzrehde opened 1 year ago

fritzrehde commented 1 year ago

Hi, I have made a little cli tool in Rust that I would like to add some tests to. I want to test the whole binary produced and check that it prints the right thing to stdout. I think this library is perfect for that use-case. However, I am a bit lost where to start. I have only ever done small unit tests in rust, not full integration tests like this one. I find the documentation of assert_cmd to be a bit lacking: In which file do I put my tests? An example skeleton of a cli integration test would be amazing! Thanks for the great work!

epage commented 1 year ago

You will need to put your tests into an integration test (under tests/) as those are compiled after your binary is.

So I've been moving my tests over to my other crate, snapbox, but it will be similar: https://github.com/gitext-rs/git-stack/blob/main/tests/testsuite/alias.rs

fritzrehde commented 1 year ago

What is snapbox? Edit: found it https://docs.rs/snapbox/latest/snapbox/ Would you recommend I use that or assert_cmd?

epage commented 1 year ago

I have three tiers of CLI testing

I suspect snapbox will get you more features and you likely won't run into the limitations of it. Like I've said, I've moved off of assert_cmd myself.

fritzrehde commented 1 year ago

I have noticed that the provided github links on https://docs.rs/snapbox/latest/snapbox/ links to trycmd. Is that on purpose? Edit: Ah, it's a subpackage, sorry for the unnecessary comment