当前位置: 首页 > news >正文

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

多级目录模块化集成测试

  • 方法一:`Cargo.toml`中为子测试目录和文件新建`[[test]]`入口
  • 方法二:在`tests/`目录的`.rs`文件中引用子目录的测试方法

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

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

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

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

[[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

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

pub mod vertex;

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

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

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

http://www.lryc.cn/news/614105.html

相关文章:

  • 线程组和线程池的基本用法
  • 【Spring Boot 快速入门】八、登录认证
  • duxapp 2025-05-29 更新 兼容鸿蒙C-API方案,现在鸿蒙端可以用于生产
  • React SSR 水合问题
  • 《告别Bug!GDB/CGDB调试实战指南》
  • TF 上架全流程实战,从构建到 TestFlight 分发
  • UniApp 跳转外部链接实现
  • Elasticsearch LTR(Learning To Rank)从训练到检索与重排
  • Elasticsearch:在向量搜索中使用 Direct IO
  • 力扣-438.找到字符串中所有字母异位词
  • ctfshow_萌新web9-web13-----rce
  • python学智能算法(三十五)|SVM-软边界拉格朗日方程乘子非负性理解
  • LeetCode 刷题【34. 在排序数组中查找元素的第一个和最后一个位置、35. 搜索插入位置】
  • 文件管理从基础到高级:文件描述符、超大文件切片重组与快速删除实战
  • 五、CV_ResNet
  • 腾讯iOA:数据安全的港湾
  • wordpress的wp-config.php文件的详解
  • proteus实现简易DS18B20温度计(stm32)
  • Linux软硬链接与动静态库
  • SQL的多表连接查询(难点)
  • 冷冻食材,鲜美生活的新选择
  • trae开发c#
  • 面试题:bable,plugin,loader,还有在打包过程中.vue/.react文件是如何转化为.js文件的
  • 解决Ollama外部服务器无法访问:配置 `OLLAMA_HOST=0.0.0.0` 指南
  • 【世纪龙科技】数智重构车身实训-汽车车身测量虚拟实训软件
  • 网络基础——网络层级
  • 库函数NTC采样温度的方法(STC8)
  • 大模型——部署体验gpt-oss-20b
  • 项目一系列-第3章 若依框架入门
  • SEABORN库函数(第十八节课内容总结)