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

相关推荐
L、2181 小时前
昇腾NPU性能调优Checklist——从“能跑“到“跑得快“的20步
服务器·人工智能·深度学习
不吃土豆的马铃薯2 小时前
Spdlog 进阶:日志基本控制、日志格式控制、异步记录器
linux·服务器·开发语言·前端·c++
疯狂成瘾者2 小时前
常见的 Linux 版本
linux·运维·服务器
GOTXX2 小时前
SenseNova U1 实战体验:API 调用 + OpenClaw 接入全流程
服务器·网络·人工智能·语言模型
l1t2 小时前
DeepSeek总结的将 Rust Delta Kernel 集成到 ClickHouse
数据库·clickhouse·rust
xingyuzhisuan2 小时前
GPU服务器集群搭建指南——选型、部署、优化+避坑全解析
运维·服务器·人工智能·gpu算力
2601_955256473 小时前
云服务器采购避坑指南:如何通过官方渠道获得更低折扣与更快服务
运维·服务器
清欢渡---3 小时前
三次握手四次挥手(对话场景)
运维·服务器·网络·hcia
小脑斧1234 小时前
从入门到精通:Linux 进程间通信 IPC 全解析|管道、共享内存、信号量、消息队列实战
linux·运维·服务器
ABCDEEE74 小时前
3.RAG
java·linux·服务器