To use embedded-test for running unit and integration tests on RISC-V, ARM, or Xtensa embedded devices, follow these steps:
- Update
Cargo.toml: Add embedded-test as a dependency. You must set harness = false for your library and tests to prevent using the standard Rust test harness. - Install the runner: Install
probe-rs-tools on your host machine. - Configure Cargo runner: In
.cargo/config.toml, set probe-rs run as the runner for your target architecture. - Configure
build.rs: Add the necessary linker arguments to include the embedded-test linker script.
probe-rs run will automatically detect if the ELF file is a standard firmware or a test binary.
[dependencies]
embedded-test = { version = "0.7.0" }
[lib]
harness = false
[[test]]
name = "example_integration_test"
harness = false
[[bin]]
name = "example_binary"
test = false
# Install the runner
cargo install probe-rs-tools
# .cargo/config.toml
[target.thumbv7em-none-eabihf]
runner = "probe-rs run --chip STM32F767ZITx"
// build.rs
fn main() {
println!("cargo::rustc-link-arg=-Tembedded-test.x");
println!("cargo::rustc-check-cfg=cfg(rust_analyzer)");
}