I’ve recently been searching for a good framework with which to write integration / system tests in Rust. The built-in testing facility gets points for being there, but doesn’t really help – it’s fine for unit tests. For integration tests, I need a setup_all function to bring the underlying system up, a setup_each function that runs before each test to reset various parts of the underlying system to a known state, several test functions to test it, and a teardown_all function to bring the system down when all tests are done. I also need the setup_all code to provide access to the underlying system as a fixture, so that tests can interact with it. With a large, growing body of such tests, the ability to run a single test – and to be able to group them into suites, and run a whole suite at a time – is also needed.

I looked at integra8 first, which seems very comprehensive, with really excellent documentation. It is currently at an ‘0.0.5-rc1’ release level – although I feel that it might need a few extra features adding before it can satisfy my requirements, above: I could not find a before_each macro, nor was there support for fixtures, or test/suite execution filtering.

I found a few things needed setting up before I had it working as I wanted, which I’ll note here. Code that uses integra8 should build as a normal Rust binary – it does not link with the libtest test runner. However, it should be located alongside the rest of the tests and use the dev-dependencies as other tests do.

The code went under the usual tests directory, as tests/e2e_integra8.rs. At the start of this code, I needed the lines:

#[cfg_attr(test, macro_use)]
extern crate integra8;
main_test! {
console_output: integra8_tree_formatter::TreeFormatter,
}

Then in Cargo.toml, under the [[dev-dependencies]] section, add integra8:

integra8 = "0.0.5-rc1"
integra8_tree_renderer = "0.0.5-rc1"

Then add a further section:

[[test]]
name = "e2e"
path = "tests/e2e_integra8.rs"
harness = false

The harness = false line is needed since integra8 is its own test runner, it does not use the built in Cargo libtest runner.

Then to launch the tests, use:

cargo test --release --test e2e

I’ll continue my investigations using rspec, as that has more of the features I need – but I’ll certainly keep an eye on integra8, it looks to be a very well-thought-out system so far, and improves on Rust’s testing framework.