You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
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/
The text was updated successfully, but these errors were encountered: