Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

post/2021/2021-01-testing-errors-in-rust/ #3

Closed
utterances-bot opened this issue May 11, 2021 · 2 comments
Closed

post/2021/2021-01-testing-errors-in-rust/ #3

utterances-bot opened this issue May 11, 2021 · 2 comments

Comments

@utterances-bot
Copy link

Testing Errors in Rust | Yury Zhauniarovich

Currently besides all other activities, I am developing a habit of programming following Test Driven Development (TDD) methodology. This is a perfect time because I continue to explore Rust, a new programming language to me. Moreover, this language encourages you to cultivate this best practice by providing great documentation and well-thought ecosystem.
In our programs, we often face with exceptional situations (e.g., lack of space when you try to write a file, or absence of a resource), and we need to handle them. If you follow the TDD approach, you need to ensure that these exceptional situations are also properly covered in your tests. Id est, you have to develop tests that reproduce these exceptional situations and make sure th

https://zhauniarovich.com/post/2021/2021-01-testing-errors-in-rust/

Copy link

Thank you for the article. I could not wrap my head around how to Assert the error_kind of my customerror in my test until I found your example:

    let actual_error_kind = read_file(Path::new("test_data/perm_denied.txt"))
        .unwrap_err()
        .kind();

What is your idea on how to organize a rust project and where to put the test files ?
I read this article rust-project-structure-example- but it would be great to read about others idea of best practice.

@zyrikby
Copy link
Owner

zyrikby commented May 12, 2021

I am not the right person to ask this question, as I am still quite new to Rust. However, The Book recommends putting unit tests into the same file into a separate tests module, while for integration tests you create a separate directory called tests and put your testing code there.

I recommend you follow this best-practice because cargo expects the tests to be located in these places. If you put them in other places it may happen that cargo will not be able to detect them. Moreover, people will look for the tests there, because this defacto is a standard.

@zyrikby zyrikby closed this as completed Jun 22, 2021
Repository owner locked and limited conversation to collaborators Jun 22, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants