In short, our requirements are: write rust integ tests that can be executed in different infra setup (server A only, server A + dep B, server A + dep B,C)
for first setup, we write integ tests under crate-a/tests/..., where crate-a is the server lib/binary
for second setup, we want to reuse integ test from crate-a, and add additional integ tests under crate-b/tests/...
similarly for third setup, we want to reuse integ tests from crate-a and crate-b with additional tests.
The only reason I can figure for wanting to do this is testing that composing libraries doesn't cause breakage. I'm not sure how that's possible, or why reusing tests in unrelated environments is more useful than testing functionality close to where it matters.
This is a disappointing hack, but you can write the shared code as a library, e.g. pub functions without #[test] annotations. It can be made it a little easier by exporting a macro that calls all of the test stubs with the annotation.
//! shared_tests.rs
#[macro_export]
macro_rules! run_tests {
() => {
use shared_tests::*;
#[test]
fn test_add_one() {
add_one();
}
// Etc.
}
}
use lib_under_test::add;
#[inline(always)]
pub fn add_one() {
let result = add(2, 2);
assert_eq!(result, 4);
}