【Rust】多级目录模块化集成测试——以Cucumber为例

多级目录模块化集成测试

方法一:Cargo.toml中为子测试目录和文件新建[[test]]入口

tests目录下新建子测试目录,比如tests/map

在tests/map中新建一个vertex.rs测试代码文件:

rust 复制代码
use cucumber::World;

// `World` is your shared, likely mutable state.
// Cucumber constructs it via `Default::default()` for each scenario.
#[derive(Debug, Default, World)]
pub struct VertexWorld {}

// This runs before everything else, so you can setup things here.
fn main() {
    // You may choose any executor you like (`tokio`, `async-std`, etc.).
    // You may even have an `async` main, it doesn't matter. The point is that
    // Cucumber is composable. :)
    futures::executor::block_on(VertexWorld::run("tests/features/map/Vertex.feature"));
}

在Cargo.toml中,多配置一组[[test]]键,并指向新的测试文件tests/map/vertex.rs:

toml 复制代码
[[test]]
name = "test_map_vertex"
path = "tests/map/vertex.rs" // 如果声明了path路径,那么name可以与文件名或test target名不同
harness = false # allows Cucumber to print output instead of libtest

命令行中执行cargo test --test test_map_vertex运行测试用例。

方法二:在tests/目录的.rs文件中引用子目录的测试方法

Cargo.toml中将[[package]]下的autotests = true启用自动发现测试目标

新建tests/map/vertex.rs:

rust 复制代码
use cucumber::World;

// `World` is your shared, likely mutable state.
// Cucumber constructs it via `Default::default()` for each scenario.
#[derive(Debug, Default, World)]
pub struct VertexWorld {}

// This runs before everything else, so you can setup things here.
pub fn test_vertex() {
    // You may choose any executor you like (`tokio`, `async-std`, etc.).
    // You may even have an `async` main, it doesn't matter. The point is that
    // Cucumber is composable. :)
    futures::executor::block_on(VertexWorld::run("tests/features/map/Vertex.feature"));
}

新建tests/map/mod.rs:

rust 复制代码
pub mod vertex;

在/tests/test.rs中引用子目录的测试方法:

rust 复制代码
mod map;

#[test]
pub fn test_vertex() {
    map::vertex::test_vertex();
}

运行cargo test,子目录的测试方法会被执行

相关推荐
liulilittle38 分钟前
Linux 下 select 测试函数
linux·服务器·网络·数据库·c++·select·c
DongQiShanRen1 小时前
玄龙(上):TICK 主循环——意识心跳怎么跳
linux·jvm·数据库·人工智能·数据挖掘·rust
luo_guibin1 小时前
Linux系统下OpenSSL升级全流程,新旧版本切换
linux·运维·服务器
看着博客敲代码1 小时前
No space left on device:服务器被 SSH 爆破到日志写满的完整排查与止血
linux·运维·服务器·安全·ssh
编程序的员1 小时前
使用OpenTelemetry来监控Rust应用
运维·rust·monitoring·opentelemetry
极光通讯2 小时前
服务器内存来料检验(IQC)实操:批次追溯、外观判定与上机验证
java·服务器·算法
Raspberry_Pi_官方账号2 小时前
Raspberry Pi Desktop 全面升级,现已登陆 PC 和 Mac
服务器·网络·macos·树莓派·raspberry pi·raspberrypios
Rooting++2 小时前
用友打包的APP壳子怎么获取SHA1码?
运维·服务器
云飞云共享云桌面2 小时前
降本 + 护图纸:珠海制造装备工厂 SolidWorks 服务器共享设计方案
运维·服务器·制造
yumgpkpm2 小时前
(CDH 7)CDP Private Cloud Base 7.3.1 → Acceldata ODP 3.3.6.4 引擎迁移风险评估表
服务器·人工智能·hadoop·python·华为·zookeeper·hbase