## 事象
以下の関数をテストするとき。
```rust
fn prints_and_returns_10(a: i32) -> i32 {
println!("I got the value {}", a);
10
}
```
`cargo test`を実行しても、[[printlnマクロ]]のメッセージが標準出力に表示されない。
## 原因
`cargo test`はデフォルトで標準出力をキャプチャするようになっているから。
## 解決方法
方法は2つある。
### `--nocapture`フラグを使う
`cargo test -- --nocapture` を実行する。以下のように[[printlnマクロ]]の結果が表示される。
```
running 2 tests
I got the value 8
I got the value 4
thread 'tests::this_test_will_failtest tests::this_test_will_pass ... ' panicked at 'okassertion failed: `(left == right)`
left: `5`,
right: `10`
```
### `--show-output`フラグを使う
`cargo test -- --show-output` を実行する。成功したテスト結果は、以下のように[[printlnマクロ]]の結果が明示的なセクションで表示される。
```
running 2 tests
test tests::this_test_will_pass ... ok
test tests::this_test_will_fail ... FAILED
successes:
---- tests::this_test_will_pass stdout ----
I got the value 4
successes:
tests::this_test_will_pass
failures:
---- tests::this_test_will_fail stdout ----
I got the value 8
thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)`
left: `5`,
right: `10`', src\lib.rs:19:9
```