当前位置: 首页 > 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.dtcms.com/a/320976.html

相关文章:

  • 服务器登上去,显示 failed to send WATCHDOG 重启有效吗?
  • 当服务器多了时,如何管理?
  • 机柜内部除了服务器还有哪些组件?
  • 防火墙概述
  • 手动开发一个TCP服务器调试工具(四):构建完整的UI与功能联合的TCP服务器应用
  • 脚本统计MongoDB集合结构信息
  • 从0开始的中后台管理系统-5(userList动态展示以及上传图片和弹出创建用户表单)
  • 【MongoDB学习笔记1】MongoDB的常用命令介绍-数据库操作、集合操作、文档操作、文档分页查询、高级查询
  • 操作系统: 线程(Thread)
  • Lazada东南亚矩阵营销破局:指纹手机如何以“批量智控+数据中枢”重构运营生态
  • Android 之 OOM的产生和解决办法
  • Android 之 ANR问题的全面解析与优化方案
  • 综合项目记录:自动化备份全网服务器数据平台
  • 日本站群服务器与普通日本服务器对比
  • 深入解析C++流运算符(>>和<<)重载:为何必须使用全局函数与友元机制
  • [论文阅读] 人工智能 + 软件工程 | LLM协作新突破:用多智能体强化学习实现高效协同——解析MAGRPO算法
  • 在发布应用程序内测时如何选择合适的分发上架方式?
  • Vite 深度解析:现代前端开发引擎
  • 瑞利杂波背景下不同环境的虚警概率与目标检测概率仿真
  • C# 异步编程(GUI程序中的异步操作)
  • 日常开发-5,工具使用。datagrip mysql 写查询语句 数据库表名和字段 无法提示
  • 语音识别 SenseVoice与FunASR对比
  • 机器学习——07 朴素贝叶斯
  • 数据结构(二叉树)
  • C++ 模拟实现 map 和 set:掌握核心数据结构
  • Jmeter接口测试实例
  • Idea配置——build system的选项区别
  • 经常问的14002
  • 5.0.9 C# wpf通过WindowsFormsHost嵌入winform控件
  • hive-日期拆分为多行