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

【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.xdnf.cn/news/17211.html

相关文章:

  • 深入探索 PDF 数据提取:PyMuPDF 与 pdfplumber 的对比与实战
  • PCB焊盘脱落的补救办法与猎板制造优势解析
  • 五种IO模型 阻塞IO 多路转接之select 多路转接之poll
  • AI学习笔记三十五:实时传输视频
  • python应用GRPC || consul 服务注册发现
  • GraphRAG 入门教程:从原理到实战
  • 碰一碰NFC开发写好评php语言源码
  • day21|学习前端vue3框架和ts语言
  • 什么是SpringBoot
  • Spring事务失效场景?
  • TCP粘包问题详解与解决方案
  • 使用SETNX实现分布式锁
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘spacy’问题
  • 【C#补全计划:类和对象(九)】接口
  • 嵌入式开发硬件——单片机
  • QtC++ 中使用 qtwebsocket 开源库实现基于websocket的本地服务开发详解
  • Java中接口与抽象类
  • 【MATLAB】(十)符号运算
  • idea开发工具中git如何忽略编译文件build、gradle的文件?
  • 为什么 `source ~/.bashrc` 在 systemd 或 crontab 中不生效
  • 安卓开发:网络状态监听封装的奥秘
  • vLLM:彻底改变大型语言模型推理延迟和吞吐量
  • 【Apache Olingo】全面深入分析报告-OData
  • count(0),count(*),count(1),count(列)有什么区别?
  • Caffeine 三种过期策略详解
  • java - 深拷贝 浅拷贝
  • 大模型2位量化原理解析
  • 【线性代数】5特征值和特征向量
  • “认知裂缝边缘”地带
  • 共识算法介绍