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

The program input and output need some testing #3

Open
gonzalo-bulnes opened this issue Oct 7, 2018 · 3 comments
Open

The program input and output need some testing #3

gonzalo-bulnes opened this issue Oct 7, 2018 · 3 comments
Labels
help me learn Rust! I'm not sure how to do this, but would love to learn from you help wanted Extra attention is needed

Comments

@gonzalo-bulnes
Copy link
Owner

gonzalo-bulnes commented Oct 7, 2018

The main function needs some refactoring (for example: #4).
But refactoring requires being able to run some tests to ensure that the code behaviour hasn't changed.

I like to use dependency injection, and replacing STDIN, STDOUT by variables to test the output of my command line programs (example code, test).

I'm not sure how to achieve that in Rust yet, and would appreciate any suggestion!

@gonzalo-bulnes gonzalo-bulnes added the help wanted Extra attention is needed label Oct 7, 2018
@gonzalo-bulnes gonzalo-bulnes added the help me learn Rust! I'm not sure how to do this, but would love to learn from you label Oct 7, 2018
@sebglazebrook
Copy link

So rust has a basic testing library built in. It works for most cases and depending on what you want to do it should suffice.

Mocking is intersting in Rust though, There are some libraries that help out in this case (https://github.com/kriomant/mockers) but they are no where near as helpful as say Rspec in Ruby. There is also a testing library that I've used before (don't remember the name but you can probably google it) that specifcally allows you to assert things related to STDOUT.

I would probably create my own mock objects that adhere to the traite required and then assert on that.

Does that make sense?

@gonzalo-bulnes
Copy link
Owner Author

[...] that specifcally allows you to assert things related to STDOUT.

💡 And yes, this does make sense, I'll take a look at how that library works.

@gonzalo-bulnes
Copy link
Owner Author

I haven't looked a this super closely, but the test example in the accepted answer to this question looks like what I was referring to in Golang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help me learn Rust! I'm not sure how to do this, but would love to learn from you help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants