Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some help with getting started #162

Open
fritzrehde opened this issue Jan 31, 2023 · 4 comments
Open

Some help with getting started #162

fritzrehde opened this issue Jan 31, 2023 · 4 comments

Comments

@fritzrehde
Copy link

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
Copy link
Contributor

epage commented Jan 31, 2023

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
Copy link
Author

fritzrehde commented Jan 31, 2023

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

@epage
Copy link
Contributor

epage commented Jan 31, 2023

I have three tiers of CLI testing

  • trycmd for snapshot testing simple commands en masse
  • snapbox for snapshot testing individual commands
  • assert_cmd for very specialized cases

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
Copy link
Author

fritzrehde commented Jan 31, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants