Rust unit testing: buffered file reading
jorgeortiz.dev·6d·
Discuss: r/rust
⚙️Systems Programming
Preview
Report Post

In the previous article, I explained how to use a test double to replace a File instance and control the behavior required by a function that reads from it. With the test double in place, I was able not only to return what I needed for the scenarios where I needed reading, but also to produce errors that allowed me to test the not-so-happy path.

I got some concerned comments pointing out that the test code wasn’t reading, which was an essential part of what we were testing. I agree that the test code isn’t actually reading. It isn’t, and that is on purpose. On the one hand, reading isn’t an essential part of what we are testing. On the contrary, File is a dependency of the are_there_vulnerable_locations() met…

Similar Posts

Loading similar posts...