2 个版本

0.1.1 2022 年 6 月 28 日
0.1.0 2022 年 6 月 28 日

#20#test-harness

MIT 许可证

5KB
54

Rust no_std 嵌入式测试框架

目前仅支持 ARM Cortex-M 半主机模式。

使用方法

embedded_test_harnesstestmacro = { git = "https://github.com/yhql/testmacro"} 添加到 Cargo.toml dev-dependencies

然后你可以按照以下模板编写测试

#![no_std]
#![cfg_attr(test, no_main)]
#![reexport_test_harness_main = "test_main"]
#![feature(custom_test_frameworks)]
#![test_runner(test_runner)]

use panic_semihosting as _;

#[cfg(test)]
use embedded_test_harness::test_runner;

#[cfg(test)]
mod tests {
    use testmacro::test_item as test;
    use embedded_test_harness::TestType;

    #[test]
    fn it_works() {
        let result = 2 + 2;
        assert_eq!(result, 4);
    }
}

/// _start is the entrypoint specified in the linker
#[no_mangle]
pub fn _start() -> ! {
    #[cfg(test)]
    test_main();

    loop {}
}

参考资料

依赖

~615KB