IntelliJ/IDEA run rust unit test, show output

  1. Problem: When I am running a unit test in IntelliJ Idea (by clicking on the green triangle), and the test passes, all the println! output is hidden. This is annoying as I often like to abuse the testing infrastructure to run small snippets of code and inspect the output.

  2. It appears the reason is related to https://stackoverflow.com/questions/25106554/why-doesnt-println-work-in-rust-unit-tests and the solution is to add --no-capture.

  3. Question: how do I tlel IntelliJ/IDEA’s Rust plugin to add --no-capture everywhere?

Here’s a way to do it:
image
Click on Edit Configurations


Edit the command field to include the following arguments after test:

-- --nocapture

Then click Ok/Apply and then run to your heart’s content.
The unfortunate downside is that this is no longer recognized as a testing suite for IntelliJ, so you will need to create a new separate command to run this without the -- --nocapture piece.

1 Like