The Test Library

1
assert_cmd 

assert_cmd库

Uses the assert_cmd crate to test the output of a binary called “hello”. The test case verifies that executing the “hello” binary is successful and that the stdout (standard output) matches the expected string “Hello, world!\n”.

1
2
3
4
5
6
7
8
use assert_cmd::Command;

#[test]
fn work(){
let mut cmd = Command::cargo_bin("hello").unwrap();
cmd.assert().success();
cmd.assert().success().stdout("Hello, world!\n");
}