【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,子目录的测试方法会被执行

相关推荐
pixcarp13 小时前
知识库系统的内容资产闭环怎么设计
服务器·数据库·后端·golang
红尘散仙13 小时前
别再手动录屏了:用 VHS 给终端应用生成会动的文档素材
后端·rust
莫名的好感°16 小时前
手机RAR解压怎么选?2026年二季度四款产品问答
服务器·网络·智能手机
Cinema KI17 小时前
Linux第一个系统程序-进度条
linux·服务器
茉莉玫瑰花茶19 小时前
综合案例 - AI 智能租房助手 [ 5 ]
服务器·数据库·人工智能·python·ai
ShineWinsu19 小时前
对于Linux:线程概念与分页存储管理的解析
linux·运维·服务器·面试·线程·进程·虚拟空间地址
x***r15121 小时前
.NET 10 SDK 安装教程(dotnet-sdk-10.0.100-win-x64详细步骤)
java·服务器·前端
鹤落晴春21 小时前
RH124问答5:管理本地用户和组
linux·运维·服务器
女神下凡21 小时前
这是 Cursor(Composer) 的五种核心交互模式
服务器·人工智能·windows·vscode·microsoft
techdashen21 小时前
从 Windows 的 ping.exe 入手:动态库、调用约定与 Rust FFI
开发语言·windows·rust