Skip to main content

Crate test_bin

Crate test_bin 

Source
Expand description

A module for getting the crate binary in an integration test.

If you are writing a command-line interface app then it is useful to write an integration test that uses the binary. You most likely want to launch the binary and inspect the output. This module lets you get the binary so it can be tested.

§Examples

basic usage:

let output = test_bin::get_test_bin("my_cli_app")
    .output()
    .expect("Failed to start my_cli_app");
assert_eq!(
    String::from_utf8_lossy(&output.stdout),
    "Output from my CLI app!\n"
);

Refer to the std::process::Command documentation for how to pass arguments, check exit status and more.

NOTE: The get_test_bin function was deprecated in version 0.5.0 in favor of the get_test_bin! macro and then undeprecated in version 0.6.0. The macro was added because there was talk of changing cargo so the function wouldn’t work. Fortunately, cargo was changed so that the macro wasn’t needed. The get_test_bin function is the recommended way of using this crate. See Cargo issue 14125.

The get_test_bin! macro uses the CARGO_BIN_EXE_<name> environment variable which was introduced in Rust 1.43 released on 23 April 2020.

Macros§

get_test_bin
Returns the crate’s binary as a Command that can be used for integration tests.

Functions§

get_test_bin
Returns the crate’s binary as a Command that can be used for integration tests.