Consider using snapshot tests
spenserblack opened this issue · 1 comments
When reviewing the code, I noticed an it_works
function that just used a bunch of println!
s without asserting anything, which I assume is to act as a test for "human eyes" instead of a programmed assertion. To me, that looks like the perfect type of test to be a snapshot test.
I use insta
a lot for this. insta
has a few assert_*_snapshot
macros that will write a snapshot to a name_of_snapshot.snap.new
file, which you can then review and remove the .new
to "accept" the snapshot (cargo-insta
is a helper that can make this easier).
Example
Here's some usage I've used in my own repo with some decent success:
https://github.com/spenserblack/gengo/blob/9229e6a46a185ed862517fb6af3e94e5193e2eb2/gengo-bin/tests/test_cli.rs#L49-L53
https://github.com/spenserblack/gengo/blob/9229e6a46a185ed862517fb6af3e94e5193e2eb2/gengo-bin/tests/snapshots/test_cli__color_javascript_repo.snap#L1-L7
Just use cat path/to/snapshot
and you can see the colorized output in your terminal (depending on your environment, of course).
Yep, agreed, that would be a good way to test it.