Allow user interaction in integration tests

The title says it all. I've been adding integration tests to my CLI project and most of the tests work. However some tests fail because some commands in my project prompt users with selection menus. So is there any way for me to allow user interaction in integration tests?

Here is an excerpt of the test that is failing:

pub fn run_command_visible(args: Vec<&str>) -> std::io::Result<()> {
    match Command::new("ferium").args(args).status() {
        Ok(_) => Ok(()),
        Err(err) => Err(err),
    }
}

#[test]
fn remove() -> std::io::Result<()> {
    println!("Remove both mods:");
	run_command_visible(vec!["remove"])?;
	assert!(run_command(vec!["list"]).is_err());

	Ok(())
}

You need to write to stdin if you want to test interactive user input. You can do that yourself, or there's assert_cmd which eases that process.

Command::write_stdin

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.