11 个版本 (4 个破坏性版本)

0.5.1 2023年8月12日
0.5.0 2023年8月9日
0.4.0 2023年7月30日
0.3.1 2023年7月15日
0.1.0 2022年12月26日

#84测试

Download history 1/week @ 2024-04-13 29/week @ 2024-04-20 229/week @ 2024-04-27 87/week @ 2024-05-04 16/week @ 2024-05-11 1/week @ 2024-05-18 72/week @ 2024-06-29 54/week @ 2024-07-27

每月118 次下载
3 crates 中使用

MIT 许可证

355KB
7K SLoC

Tests Workflow Status (main) Crates.io docs.rs

xpct

xpct 是一个针对 Rust 的可扩展测试断言库。它旨在易于使用、功能齐全,并且与测试框架无关。

想要开始吗? 查看教程

关于

xpct 是可扩展的。除了允许你编写自定义匹配器外,它还分离了匹配器的逻辑和它们输出格式化的方式,这意味着你可以

  1. 连接到现有的格式化程序来编写具有美观输出的自定义匹配器,而无需担心格式化。
  2. 自定义现有匹配器的格式化,而无需重新实现它们的逻辑。

该软件包旨在提供许多有用的匹配器。查看提供的匹配器的完整列表

文档

示例

一个简单的等式断言,如 assert_eq

use xpct::{expect, equal};

expect!("disco").to(equal("Disco"));
stderr from failed assertion

图像转录

解包 Some 值以对包装的值进行断言

use xpct::{be_gt, be_some, expect};

expect!(Some(41))
    .to(be_some())
    .to(be_gt(57));
stderr from failed assertion

图像转录

对结构体单个字段进行断言

use xpct::{be_empty, be_in, be_true, expect, fields, have_prefix, match_fields, not, why};

struct Player {
    id: String,
    name: String,
    level: u32,
    is_superstar: bool,
}

let player = Player {
    id: String::from("REV12-62-05-JAM41"),
    name: String::from(""),
    level: 21,
    is_superstar: false,
};

expect!(player).to(match_fields(fields!(Player {
    id: have_prefix("REV"),
    name: not(be_empty()),
    level: be_in(1..=20),
    is_superstar: why(be_true(), "only superstars allowed"),
})));
stderr from failed assertion

图像转录

对集合中的元素进行断言

use xpct::{be_in, contain_substr, equal, expect, have_len, match_elements};

let items = vec!["apple", "pear", "banana"];

expect!(items)
    .to(have_len(3))
    .to(match_elements([
        contain_substr("ana"),
        equal("pear"),
        be_in(["mango", "orange"]),
    ]));
stderr from failed assertion

图像转录

显示数据结构的丰富差异

use xpct::{eq_diff, expect};

expect!(["apple", "banana"]).to(eq_diff(["banana", "orage"]));
stderr from failed assertion

图像转录

MSRV 策略

支持最后两个稳定的 Rust 版本。较旧的版本也可能得到支持。

MSRV 只在必要时增加——不是每次有新的 Rust 版本都会增加。如果 >=1.0.0,则 MSRV 的增加将伴随一个次版本号的轻微增加;如果 <1.0.0,则伴随一个补丁版本号的增加。

语义版本控制策略

在版本 1.0.0 之前,破坏性更改将伴随一个次版本号的增加,而新功能和错误修复将伴随一个补丁版本号的增加。

依赖关系

~0.2–11MB
~63K SLoC