Cargo watch has been a game changer in productivity

78 points sunmoi

Running

cargo watch -x 'test test_name -- --nocapture'

Allows you to run one particular test every you save a file in your crate, it also lets any info you're printing using dbg! to still appear when the test runs.

This is amazing, not for running tests, but for having a tight feedback loop when developing new features. Simply write a little harness to prepare some test input, and keep writing code in the test until you're transforming the data like you want, using dbg! to inspect whats happening. Once it works, refactor that code out of the test into the rest of the project.

Lets you have a similar (in spirit) workflow to a repl, where you can write code in small chunks, verifying at every step. Also avoids the pitfalls of going for a true TDD approach where you have to write the expected output ahead of time.

Once you know what the output should look like, you can harden it into a real test case.