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

相关推荐
我爱吃土豆16 小时前
AI 编程工具远程开发指南:Codex 桌面版与 WorkBuddy 通过 SSH 连接云服务器实践
服务器·人工智能·ssh
一技安身7 小时前
【信创】银河麒麟V10、统信UOS解压7Z文件
linux·运维·服务器
Dawn-bit9 小时前
Linux 运维基础扩展:跳板机、堡垒机与物理服务器全流程
linux·运维·服务器·云计算·运维开发
新时代牛马9 小时前
Linux 定时任务:crontab、anacron 与systemd timer
linux·运维·服务器
IT摆渡者9 小时前
1panel 配置申请手动解析网站SSL证书
服务器·网络协议·ssl
传奇开心果编程9 小时前
【Xilem基础语法学与练】第7课:Xilem与Masonry底层构建技术解析
学习·rust·前端框架
疯狂打码的少年9 小时前
【计算机网络】子网掩码与子网划分计算(含CIDR表示法)
服务器·笔记·计算机网络·php
网硕互联的小客服10 小时前
怎样在CMD里用chkntfs /x C: 命令来取消磁盘自检?——原理与实践全解
运维·服务器·网络
布莱克60510 小时前
Linux 常用命令详解:从入门到实战
linux·运维·服务器
学习路上_write12 小时前
Linux黑马命令学习
linux·运维·服务器