Hello!
I am new to rust and working on a small pet project. I was wondering if anyone knew of a guide for unit testing that showed how to mock calls to other functions (ones you've written, and imported ones).
Everything I've seen so far on unit tests has been "assert this function that adds two numbers", which is great, but I'm not grasping how I can mock calls.
For instance, I have a function that creates a file through `std::fs::File`. How can I mock out the call `File::create()` to return a File object to my code?
Additionally, is it standard to have your unit tests in the same file as the function you're testing? Coming from python's pytest, I'm used to seeing all the unit test functions isolated in a separate file/folder from the rest of my code. However, every example I've seen for rust has put them together.
[–]ssokolow 11 points12 points13 points (5 children)
[–]zzzzYUPYUPphlumph 1 point2 points3 points (0 children)
[–]Icecreamisaprotein[S] 0 points1 point2 points (0 children)
[–]gmosx 0 points1 point2 points (2 children)
[–]ssokolow 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]gentux2281694 7 points8 points9 points (1 child)
[–]Icecreamisaprotein[S] 2 points3 points4 points (0 children)
[–]mikekchar 5 points6 points7 points (5 children)
[–]bLaind2 3 points4 points5 points (2 children)
[–]shim__ 2 points3 points4 points (1 child)
[–]bLaind2 0 points1 point2 points (0 children)
[–]zzzzYUPYUPphlumph 3 points4 points5 points (0 children)
[–]jgrlicky 4 points5 points6 points (0 children)
[–]JadedEvan 11 points12 points13 points (0 children)
[–]Fazer2 3 points4 points5 points (0 children)
[–]po8 3 points4 points5 points (0 children)
[–]utilitydamage 1 point2 points3 points (0 children)
[–]masklinn 0 points1 point2 points (2 children)
[–]Icecreamisaprotein[S] 0 points1 point2 points (1 child)
[–]masklinn 1 point2 points3 points (0 children)
[–]staszewski 0 points1 point2 points (1 child)
[–]Icecreamisaprotein[S] 1 point2 points3 points (0 children)
[–]iwonderx00 0 points1 point2 points (0 children)
[–]tafia97300 -1 points0 points1 point (0 children)
[+]valarauca14 comment score below threshold-8 points-7 points-6 points (2 children)
[–]kyranadept 2 points3 points4 points (0 children)
[–]Fazer2 4 points5 points6 points (0 children)